Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javascriptдÀ෽ʽ֮ËÄ

ͨ¹ýÇ°Ãæ¼¸ÆªµÃÖªjavascriptдÀàÎÞ·Ç»ùÓÚ¹¹Ô캯Êý
ºÍÔ­ÐÍ
¡£¼ÈÈ»ÕâÑù£¬ÎÒÃÇд¸ö¹¤¾ßº¯ÊýÀ´Ð´Àà¡£
/**
* $class дÀ๤¾ßº¯ÊýÖ®Ò»
* @param {Object} constructor
* @param {Object} prototype
*/
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
c.prototype = p;
return c;
}

àÅ¡£¹¤¾ßÀàдºÃÁË£¬À´×é×°Ï£ºÓù¹Ô캯ÊýÀ´Éú³ÉÀàʵÀýµÄÊôÐÔ£¨×ֶΣ©£¬Ô­ÐͶÔÏóÓÃÀ´Éú³ÉÀàʵÀýµÄ·½·¨¡£
//¹¹Ô캯Êý
function Person(name) {
this.name = name;
}
//Ô­ÐͶÔÏó
var proto = {
getName : function(){return this.name},
setName : function(name){this.name = name;}
}
//×é×°
var Man = $class(Person,proto);
var Woman = $class(Person,proto);

ok£¬ÕâʱºòÒѾ­µÃµ½ÁËÁ½¸öÀàMan£¬Woman¡£²¢ÇÒÊÇͬһ¸öÀàÐ͵ġ£²âÊÔÈçÏ£º
console.log(Man == Woman);//true
console.log(Man.prototype == Woman.prototype);//true

´´½¨¶ÔÏó¿´¿´£¬
var man = new Man("Andy");
var woman = new Woman("Lily");
console.log(man instanceof Man);//true
console.log(woman instanceof Woman);//true
console.log(man instanceof Person);//true
console.log(woman instanceof Person);//true

okÒ»ÇÐÈçÎÒÃÇËùÆÚÍû¡£µ«ÊÇÓиöÎÊÌ⣬ÏÂÃæ´úÂëµÄ½á¹ûÊä³öfalse£¬
console.log(man.constructor == Person);//false

ÕâÈÃÈ˲»Ô㺴ÓÒÔÉϵĴúÂë¿´³ömanµÄÈ·ÊÇͨ¹ýManÀànew³öÀ´µÄ var man = new Man("Andy")£¬ÄÇô¶ÔÏóʵÀýmanµÄ¹¹ÔìÆ÷Ó¦¸ÃÖ¸ÏòMan£¬µ«ÎªºÎÊÂÓëÔ¸Î¥ÄØ£¿
Ô­Òò¾ÍÔÚÓÚ$classÖÐÖØÐ´ÁËPersonµÄÔ­ÐÍ£ºc.prototype = p;
ºÃÁË£¬ÎÒÃǰÑ$classÉÔ΢¸ÄдÏ£¬½«·½·¨¶¼¹ÒÔÚ¹¹ÔìÆ÷µÄÔ­ÐÍÉÏ£¨¶ø²»ÊÇÖØÐ´¹¹ÔìÆ÷µÄÔ­ÐÍ£©£¬ÈçÏ£º
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
// c.prototype = p;
for(var atr in p)
c.prototype[atr] = p[atr];
return c;
}


Ïà¹ØÎĵµ£º

javascriptЧÂʾ­Ñé̸(Ò»)

±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔ­À´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾­Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾­¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷Ô­Òò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......

javascript³£ÓÃ

calcu()  ----º¯ÊýʵÏÖÁ½¸öÊýÏà³Ë
document.write();  ---´òÓ¡
document.calc.ÔªËØÃû.value;  --»ñµÃ±íµ¥µÄÖµ
document.±íµ¥Ãû¡£±íµ¥ÔªËØÃû¡£value  Ϊ±íµ¥¸³Öµ
¶¨Ò庯Êý£º
 function  Ãû×Ö()
 {
    //javaScriptÔ¤Óï¾ä
 }
 onClick="º¯ÊýÃû";  ......

[·­Òë]High Performance JavaScript(003)

Dynamic Script Elements  ¶¯Ì¬½Å±¾ÔªËØ
    The Document Object Model (DOM) allows you to dynamically create almost any part of an HTML document using JavaScript. At its root, the <script> element isn't any different than any other element on a page: references can be retrie ......

[·­Òë]High Performance JavaScript(005)

µÚ¶þÕ  Data Access  Êý¾Ý·ÃÎÊ
    One of the classic computer science problems is determining where data should be stored for optimal reading and writing. Where data is stored is related to how quickly it can be retrieved during code execution. This problem in JavaScri ......

javascriptдÀ෽ʽ֮Èý

È¡Ç°ÃæÁ½ÖÖµÄÓŵ㣺
a¡¢Óù¹Ô캯ÊýÀ´¶¨ÒåÀàÊôÐÔ£¨×ֶΣ©
b¡¢ÓÃÔ­ÐÍ·½Ê½À´¶¨ÒåÀàµÄ·½·¨¡£
¾ÍÓÐÁ˵ÚÈýÖÖ·½Ê½¡£ÕâÖÖ·½Ê½Ã²ËƲÉÓõÄÈ˽϶ࡣ
3¡¢×ۺϹ¹Ô캯Êý/Ô­ÐÍ
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Pers ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ