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

javascript prototype½éÉܵÄÎÄÕÂ

JavaScriptÊÇ»ùÓÚ¶ÔÏóµÄ£¬ÈκÎÔªËض¼¿ÉÒÔ¿´³É¶ÔÏó¡£È»¶ø£¬ÀàÐͺͶÔÏóÊDz»Í¬µÄ¡£±¾ÎÄÖУ¬ÎÒÃdzýÁËÌÖÂÛÀàÐͺͶÔÏóµÄһЩÌصãÖ®Í⣬¸üÖØÒªµÄÊÇÑо¿ÈçºÎд³öºÃµÄ²¢ÇÒÀûÓÚÖØÓõÄÀàÐÍ¡£±Ï¾¹£¬JavaScriptÕâÖÖÁ÷ÐеĽű¾ÓïÑÔÈç¹ûÄܹ»½øÐÐÁ¼ºÃµÄ·â×°£¬²¢ÐγÉÒ»¸öÅÓ´óµÄÀàÐͿ⣬¶ÔÓÚÖØÓÃÊǷdz£ÓÐÒâÒåµÄ¡£
ÍøÉ϶ÔÓÚprototypeµÄÎÄÕºܶ࣬һֱûÃ÷°×ºËÐĵÄ˼Ïë¡£×îºóдÁ˺ܶàÀý×Ó´úÂëºó²ÅÃ÷°×£ºprototypeÖ»ÄÜÓÃÔÚÀàÐÍÉÏ¡£
ÒÔÏÂÊÇһЩ¹ØÓÚÀàÐͺͶÔÏóµÄÀý×Ó£¬´ó¼Ò¿´ÍêÀý×Óºó¿ÉÄܸüÈÝÒ×Àí½âÀàÐͺͶÔÏóÖ®¼äµÄÁªÏµ£º
 
  Àý×Ó´úÂë ˵Ã÷
1 Object.prototype.Property = 1;
Object.prototype.Method = function ()
{
    alert(1);
}
 
var obj = new Object();
alert(obj.Property);
obj.Method();
¿ÉÒÔÔÚÀàÐÍÉÏʹÓÃproptotypeÀ´ÎªÀàÐÍÌí¼ÓÐÐΪ¡£ÕâЩÐÐΪֻÄÜÔÚÀàÐ͵ÄʵÀýÉÏÌåÏÖ¡£
JSÖÐÔÊÐíµÄÀàÐÍÓÐArray, Boolean, Date, Enumerator, Error, Function, Number, Object, RegExp, String
2 var obj = new Object();
obj.prototype.Property = 1; //Error
//Error
obj.prototype.Method = function()
{
    alert(1);
}
ÔÚʵÀýÉϲ»ÄÜʹÓÃprototype£¬·ñÔò·¢Éú±àÒë´íÎó
3 Object.Property = 1;
Object.Method = function()
{
    alert(1);
}
 
alert(Object.Property);
Object.Method();
¿ÉÒÔΪÀàÐͶ¨Ò哾²Ì¬”µÄÊôÐԺͷ½·¨£¬Ö±½ÓÔÚÀàÐÍÉϵ÷Óü´¿É
4 Object.Property = 1;
Object.Method = function()
{
    alert(1);
}
var obj = new Object();
alert(obj.Property); //Error
obj.Method(); //Error
ʵÀý²»Äܵ÷ÓÃÀàÐ͵ľ²Ì¬ÊôÐÔ»ò·½·¨£¬·ñÔò·¢Éú¶ÔÏó䶨ÒåµÄ´íÎó¡£
5 function Aclass()
{
this.Property = 1;
this.Method = function()
{
    alert(1);
}
}
var obj = new Aclass();
alert(obj.Property);
obj.Method();
Õâ¸öÀý×ÓÑÝʾÁËͨ³£µÄÔÚJavaScriptÖж¨ÒåÒ»¸öÀàÐ͵ķ½·¨
6 function Aclass()
{
this.Property = 1;
this.Method = function()
{
    alert(1);
}
}
Aclass.prototype.Property2 = 2;
Aclass.prototype.Method2 = function
{
    alert(2);
}
var obj = new Aclass();
alert(obj.Property2);
obj.Method2();
¿ÉÒÔÔÚÍ


Ïà¹ØÎĵµ£º

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

String Trimming  ×Ö·û´®ÐÞ¼ô
    Removing leading and trailing whitespace from a string is a simple but common task. Although ECMAScript 5 adds a native string trim method (and you should therefore start to see this method in upcoming browsers), JavaScript has not historically in ......

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

Yielding with Timers  Óö¨Ê±Æ÷Èóöʱ¼äƬ
    Despite your best efforts, there will be times when a JavaScript task cannot be completed in 100 milliseconds or less because of its complexity. In these cases, it's ideal to yield control of the UI thread so that UI updates may occur ......

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

Fiddler
    Fiddler is an HTTP debugging proxy that examines the assets coming over the wire and helps identify any loading bottlenecks. Created by Eric Lawrence, this is a general purpose network analysis tool for Windows that provides detailed reports on any browser or web request. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ