JavascriptµÄÔÐͶÔÏóºÍprototypeÊôÐÔ
JavascriptÖеļ̳лúÖÆÊÇËùνµÄÔÐͶÔÏó¼Ì³Ð£¬Í¨¹ýÊôÐÔ·ÃÎÊ»úÖƵÄÌØÊâÐÔÀ´ÊµÏּ̳еġ£Ö®Ç°ÎÒÒ»Ö±ÒÔΪËùÓжÔÏóµÄÔÐͶÔÏó¾ÍÊÇprototypeËùÖ¸µÄÄǸö¶ÔÏ󡣺óÀ´ÔÚ¿´javascriptÉè¼ÆģʽµÄʱºò·¢ÏÖ×÷Õß×¢ÖÐÓÐÒ»¾ä»°ÓëÎÒ֮ǰµÄÀí½â²»Í¬£¬Ëû˵“ÿ¸ö¶ÔÏó¶¼ÓÐÒ»¸öÔÐͶÔÏ󣬵«Õâ²¢²»Òâζ×Åÿ¸ö¶ÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ”¡£¿´ÍêÎÒ¾ÍÓеãÃÔãÁË£¬¾ö¶¨³¹µ×°ÑÕâ¸öËÀÈ˵ÄÔÐͼ̳иã¸ãÇå³þ¡£È»ºó·ÁËЩÎÄÕºÍÊé¼®£¬×îºóÖÕÓÚÔÚjavascriptȨÍþÖ¸ÄϵÚÎå°æÖÐÕÒµ½Á˸öÈË ÈÏΪ±È½ÏȨÍþµÄ½âÊÍ¡£¹ØÓÚÔÐÍÁ´ºÍÊôÐÔ·ÃÎÊ»úÖÆÎҾͲ»ÔÙ²ûÊöÁË£¬Õâ·½Ãæ¿ÉÒÔ¿´¿´RockyµÄÎÄÕ дµÄÂùÇå³þµÄ http://blog.csdn.net/rocky_j2ee/archive/2009/03/21/4012385.aspx
ÄÇÎÒÃÇÏÈ´Ó´´½¨¶ÔÏó˵Æð£¬ÓÃnew²Ù×÷·û´´½¨¶ÔÏóµÄʱºòjavascript»á×ö3¼þÊ£º
Ê×ÏÈÊÇ´´½¨Ò»¸ö¿Õ¶ÔÏó£¨empty object£©£¬
È»ºó¶ÔÕâ¸ö¿Õ¶ÔÏóµÄÔÐͶÔÏó½øÐи³Öµ£¬
×îºó°ÑÕâ¸ö¿Õ¶ÔÏó¸³Öµ¸ø¹¹Ô캯ÊýµÄthisÊôÐÔÇÒÔËÐÐÕâ¸ö¹¹Ô캯Êý¡£
function Person(name) {
this.name = name;
}
var p = new Person();
Ï൱ÓÚÒÔϲ½Ö裺
1. Var p = {};
2. p.[[prototype]] = Person.prototype
//ÕâÒ»²½ÊÇα´úÂ룬ʵ¼ÊÉÏÒ»¸ö¶ÔÏóµÄÔÐͶÔÏóÊDz»ÄÜͨ¹ý´úÂëÀ´·ÃÎʵģ¬
//ÕâÀïÖ»ÊÇΪÁË˵Ã÷´´½¨¶ÔÏóµÄ²½Öè
3. p.methodName = Person
; //ÕâÑùµÄ»°PersonµÄthis¾Í»áÖ¸Ïòp
p.methodName();
Èç¹ûÄã¶ÔµÚ¶þ²½²»ÊǺÜÃ÷°×£¬ÄÇôÏÈ°Ñ´úÂë·ÅÒ»·Å£¬½ÓÏÂÀ´ÎÒ»áÏêϸ½âÊÍϵڶþ²½ÔÐͶÔÏóµÄ¸³Öµ£¨»òÕß˵¹¹Ô캯ÊýºÍÔÐͶÔÏóµÄ¹Øϵ£©:ÉÏÃæÎÒÌáµ½¹ýÔÚ´´½¨ÍêÒ»¸ö¿Õ¶ÔÏóºó£¬»á³õʼ»¯Õâ¸ö¿Õ¶ÔÏóµÄÔÐͶÔÏó£¬javascript»á°Ñ¹¹Ô캯ÊýµÄÒ»¸ö½Ð×öprototypeµÄÊôÐÔËùÖ¸ÏòµÄ¶ÔÏó¸³Öµ¸øµ±Ç°¿Õ¶ÔÏóµÄÔÐͶÔÏó¡£ËùÓеÄfunction¶¼ÓÐÒ»¸öprototypeÊôÐÔ£¬µ±Ò»¸öfunction±»¶¨ÒåÖ®ºóÕâ¸öÊôÐԻᱻ×Ô¶¯µÄ´´½¨ºÍ³õʼ»¯¡£Ò»¸öfunction µÄprototypeÊôÐԵijõʼֵÊÇÒ»¸ö¶ÔÏó£¨an object£©£¬Õâ¸ö¶ÔÏóÖ»ÓÐÒ»¸öÊôÐÔ½Ð×öconstructor£¬¶øÕâ¸öconstructor µÄÖµ¾ÍÊǵ±Ç°Õâ¸öº¯Êý£¨»òÕß½
Ïà¹ØÎĵµ£º
javascriptÖÐevent.keycode
keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
keycode 32 = space space ......
/**
* JavaScript ÊÇÃæÏò¶ÔÏóµÄÓïÑÔ£¬µ«ÊÇËûµÄÃæÏò¶ÔÏó²»ÊÇ»ùÓÚÀàµÄ£¬ÊÇ»ùÓÚÔÐ͵Ä;
* µ«ÊÇËûµÄһЩÌØÐÔ(º¯ÊýÊÇÊý¾Ý)£¬Ê¹µÃËü¿ÉÒÔÄ£Äâ»ùÓÚÀàµÄÃæÏò¶ÔÏ󣬵«ÊÇ JavaScript ²¢²»Ö§³ÖºÍ Java Ò»ÑùµÄÀ࣬
* Òò´Ë JavaScript ÖеÄ"Àà"¿ÉÒÔ³Æ×÷"αÀà"
*/
//
/**
* ¹¹Ô캯Êý: js ÖÐÓÃÀ´ºÍ new ÔËËã·ûÒ»ÆðʹÓõĺ¯Êý³Æ× ......
×÷ÓÃÓò Scope
Javascript Öеĺ¯ÊýÊôÓÚ´Ê·¨×÷ÓÃÓò£¬Ò²¾ÍÊÇ˵º¯ÊýÔÚËü±»¶¨ÒåʱµÄ×÷ÓÃÓòÖÐÔËÐжø²»ÊÇÔÚ±»Ö´ÐÐʱµÄ×÷ÓÃÓòÄÚÔËÐС£ÕâÊÇϬţÊéÉϵÄ˵·¨¡£µ«“¶¨Òåʱ”ºÍ“Ö´ÐУ¨±»µ÷Óã©Ê±”ÕâÁ½¸ö¶«Î÷ÓÐЩÈ˸㲻Çå³þ¡£¼òµ¥À´Ëµ£¬Ò»¸öº¯ÊýAÔÚ“¶¨Òåʱ”¾ÍÊÇ function A(){} Õâ¸öÓï¾äÖ´ÐеÄʱºò¾Í ......
µÚÒ»ÖÖ·½·¨ÈçÏÂ
if (typeof beforeReject != 'undefined' && beforeReject instanceof Function) {
beforeReject(nextStep);
}
µÚ¶þÖÖ·½·¨ÈçÏÂ
if (¶ÔÏóÃû.·½·¨Ãû)
{
//·½·¨´æÔÚ
¶ÔÏóÃû.·½·¨Ãû();
}
µÚÈýÖÖ·½·¨£º
if(typeof(nl.onBlue)=="function")
{
//´æÔÚ
}
......