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();
¿ÉÒÔÔÚÍ
Ïà¹ØÎĵµ£º
Data Format Conclusions Êý¾Ý¸ñʽ×ܽá
Favor lightweight formats in general; the best are JSON and a character-delimited custom format. If the data set is large and parse time becomes an issue, use one of these two techniques:
×ܵÄÀ´ËµÔ½ÇáÁ¿¼¶µÄ¸ñʽԽºÃ£¬× ......
µÚ°ËÕ Programming Practices ±à³Ìʵ¼ù
Every programming language has pain points and inefficient patterns that develop over time. The appearance of these traits occurs as people migrate to the language and start pushing its boundaries. Since 2005, when the term "Ajax" ......
Use the Fast Parts ʹÓÃËٶȿìµÄ²¿·Ö
Even though JavaScript is often blamed for being slow, there are parts of the language that are incredibly fast. This should come as no surprise, since JavaScript engines are built in lower-level languages and are therefore compiled. Thou ......
Firebug
Firefox is a popular browser with developers, partially due to the Firebug addon (available at http://www.getfirebug.com/), which was developed initially by Joe Hewitt and is now maintained by the Mozilla Foundation. This tool has increased the productivity of web develop ......
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. ......