javascriptдÀ෽ʽ֮Èý
È¡Ç°ÃæÁ½ÖÖµÄÓŵ㣺
a¡¢Óù¹Ô캯ÊýÀ´¶¨ÒåÀàÊôÐÔ£¨×ֶΣ©
b¡¢ÓÃÔÐÍ·½Ê½À´¶¨ÒåÀàµÄ·½·¨¡£
¾ÍÓÐÁ˵ÚÈýÖÖ·½Ê½¡£ÕâÖÖ·½Ê½Ã²ËƲÉÓõÄÈ˽϶ࡣ
3¡¢×ۺϹ¹Ô캯Êý/ÔÐÍ
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
ÕâÑù£¬¼´¿Éͨ¹ý¹¹Ô캯Êý¹¹Ô첻ͬnameµÄÈË£¬¶ÔÏóʵÀýÒ²¶¼¹²ÏígetName·½·¨£¬²»»áÔì³ÉÄÚ´æÀË·Ñ¡£
µ«ËƺõÕâÑùµÄ´úÂë·ç¸ñËƺõÈÔȻûÓÐjavaµÄÀàÄÇô½ô´Õ£¬°ÑÊôÐÔ£¬¹¹Ôì·½·¨£¨º¯Êý£©£¬·½·¨¶¼°üÔÚ´óÀ¨ºÅÄÚ¡£
public class Person {
//ÊôÐÔ£¨×ֶΣ©
String name;
//¹¹Ôì·½·¨£¨º¯Êý£©
Person(String name) {
this.name = name;
}
//·½·¨
String getName() {
return this.name;
}
}
ΪÁËÈÃjs´úÂë·ç¸ñ¸ü½ô´Õ£¬°Ñ¹ÒÔÚprototypeµÄ·½·¨´úÂëÒƵ½function PersonµÄ´óÀ¨ºÅÄÚ¡£
function Person(name) {
this.name = name;
Person.prototype.getName = function() {
return this.name;
}
}
ËƺõºÜÉñÆ棬»¹ÄÜÕâôд°¡£¡ÑéÖ¤Ò»ÏÂ
var p1 = new Person("Jack");
var p2 = new Person("Tom");
console.log(p1.getName());//Jack
console.log(p2.getName());//Tom
ûÓб¨´í£¬¿ØÖÆ̨ҲÕýÈ·Êä³öÁË¡£ËµÃ÷¿ÉÒÔÕâôд£¬ºÇºÇ¡£
àÅ£¬ËƺõºÜÍêÃÀ¡£
a ¡¢¿ÉÒÔͨ¹ý´«²Î¹¹Ôì¶ÔÏóʵÀý
b ¡¢¶ÔÏóʵÀý¶¼¹²Ïíͬһ·Ý·½·¨²»Ôì³ÉÄÚ´æÀË·Ñ
c ¡¢´úÂë·ç¸ñÒ²±È½Ï½ô´Õ
µ«Ã¿´ÎnewÒ»¸ö¶ÔÏóµÄʱºò¶¼»áÖ´ÐÐ
Person.prototype.getName = function() {
return this.name;
}
Ôì³ÉÁ˲»±ØÒªµÄÖظ´µÄÔËËã¡£ÒòΪgetName·½·¨¹ÒÔÚprototypeÉÏÖ»ÐèÖ´ÐÐÒ»´Î¼´¿É¡£Ö»ÐèÉÔ΢¸ÄÔìÏ£º
function Person(name) {
this.name = name;
if(Person._init==undefined) {
alert("ÎÒÖ»Ö´ÐÐÒ»´Î£¡");
Person.prototype.getName = function() {
return this.name;
}
Person._init = 1;
}
}
newÁ½¸ö¶ÔÏó£¬
var p1 = new Person("Andy");//µÚÒ»´Înew»áµ¯³ö'ÎÒÖ»Ö´ÐÐÒ»´Î£¡'
var p2 = new Person("Lily");//ÒÔºónewµÄ¶ÔÏó²»»áÔÙÖ´ÐÐÁË
Ïà¹ØÎĵµ£º
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; ......
¿´ÊéµÄʱºòÓöµ½ÕâÑùÒ»¸öÎÊÌ⣬³ÌÐò´úÂëÈçÏÂ
var ob = function(){
var obj = this;
function fn1(){
alert( obj === window );//false
alert( this === window );//ture
}
this.fn2 = function() {
fn1();
}
}
µ±Ê±ºÜ²»Ã÷°×fn1ÀïÃæµÚ¶þ¸öalertµÄ½á¹û£¬Îª ......
ÀàÊÇʲô£¿
Ðí¶à¸Õ½Ó´¥±à³ÌµÄÅóÓѶ¼¿ÉÄÜÀí½â²»ÁËÀ࣬ÆäʵÀàÊǶÔÎÒÃÇÕâ¸öÏÖʵÊÀ½çµÄÄ£Ä⣬°ÑËü˵³É“Àà±ð”»òÕß“ÀàÐÍ”¿ÉÄÜ»á¸üÈÝÒ×Àí½âһЩ¡£±ÈÈç“ÈË”ÕâÖÖ¶¯
Îï¾ÍÊÇÒ»¸öÀ࣬¶ø¾ßÌåijһ¸öÈ˾ÍÊÇ“ÈË”Õâ¸öÀàµÄÒ»¸öʵÀý
£¬
“È ......
Grouping Scripts ³É×é½Å±¾
Since each <script> tag blocks the page from rendering during initial download, it's helpful to limit the total number of <script> tags contained in the page. This applies to both inline scripts as well as those in external files. Every time ......