Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ¶ÔÏóµÄ±È½Ï

Õâ¸öËæ±ÊÆäʵÊÇΪÁ˸ÐлÇå·çЦ¸øµÄÒ»¸öÌáʾ£¬²»½ö½öÊǸæËßÎÒÔõôÅжÏÊý×飬¸üÈÃÎÒÓÐÁËÈÏÕæ¶ÁÒ»¶Á ¡¶javascriptȨÍþÖ¸ÄÏ¡·µÄÏë·¨¡£
±È½ÏºÍ¿½±´ÆäʵÊÇÒ»»ØÊ£¬´úÂëÈçÏ£º
//
//Compare object function
//
function Compare(fobj,sobj)
{
    var ftype = typ ......

[·­Òë]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 ......

asp.net×¢²áJavascriptµÄ·½·¨

1¡¢IsStartupScriptRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁËÆôÓýű¾¡£
2¡¢IsClientScriptBlockRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾¿é¡£
3¡¢IsClientScriptIncludeRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾°üº¬¡£
µÚÒ»¸öÀý×Ó£º
string info = "<script>alert('ÄãºÃÂð£¿');</script>";
//ÅжÏʼþÊÇ·ñ±»×¢²á£¬Ð´ÈëÇ ......

javascriptдÀ෽ʽ֮¶þ

2¡¢Ô­ÐÍ·½Ê½
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
*/
function Person(){}
Person.prototype.name = "jack";
Person.prototype.getName = function() { return this.name;}

°ÑÀàµÄÊôÐÔ£¨×ֶΣ©£¬·½·¨¶¼¹ÒÔÚprototypeÉÏ¡£
Ô켸¸ö¶ÔÏó²âÊÔÏ£º
var p1 = new Person();
var ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ