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

Javascript ±Õ°ü


·­Ò룺Ϊ֮Âþ±Ê
Á´½Ó£ºhttp://www.cn-cuckoo.com/2007/08/01/understand-javascript-closures-72.html
¼ò½é
»ùÓÚ¶ÔÏóµÄÊôÐÔÃû½âÎö
ÖµµÄÖ¸¶¨
ÖµµÄ¶ÁÈ¡
±êʶ·û½âÎö¡¢Ö´Ðл·¾³ºÍ×÷ÓÃÓòÁ´
Ö´Ðл·¾³
×÷ÓÃÓòÁ´Óë [[scope]]
±êʶ·û½âÎö
±Õ°ü
×Ô¶¯À¬»øÊÕ¼¯
¹¹³É±Õ°ü
ͨ¹ý±Õ°ü¿ÉÒÔ×öʲô£¿
Àý 1£ºÎªº¯ÊýÒýÓÃÉèÖÃÑÓʱ
Àý 2£ºÍ¨¹ý¶ÔÏóʵÀý·½·¨¹ØÁªº¯Êý
Àý 3£º°ü×°Ïà¹ØµÄ¹¦ÄÜ
ÆäËûÀý×Ó
ÒâÍâµÄ±Õ°ü
Internet Explorer µÄÄÚÔÚй©ÎÊÌâ
¼ò½é
Closure Ëùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
±Õ°üÊÇ ECMAScript £¨JavaScript£©×îÇ¿´óµÄÌØÐÔÖ®Ò»£¬µ«ÓúñհüµÄÇ°ÌáÊDZØÐëÀí½â±Õ°ü¡£±Õ°üµÄ´´½¨Ïà¶ÔÈÝÒ×£¬ÈËÃÇÉõÖÁ»áÔÚ²»¾­Òâ¼ä´´½¨±Õ°ü£¬µ«ÕâЩÎÞÒâ´´½¨µÄ±Õ°üÈ´´æÔÚDZÔÚµÄΣº¦£¬ÓÈÆäÊÇÔڱȽϳ£¼ûµÄä¯ÀÀÆ÷»·¾³Ï¡£Èç¹ûÏëÒªÑﳤ±Ü¶ÌµØʹÓñհüÕâÒ»ÌØÐÔ£¬Ôò±ØÐëÁ˽âËüÃǵŤ×÷»úÖÆ¡£¶ø±Õ°ü¹¤×÷»úÖƵÄʵÏֺܴó³Ì¶ÈÉÏÓÐÀµÓÚ±êʶ·û£¨»òÕß˵¶ÔÏóÊôÐÔ£©½âÎö¹ý³ÌÖÐ×÷ÓÃÓòµÄ½ÇÉ«¡£
¹ØÓÚ±Õ°ü£¬×î¼òµ¥µÄÃèÊö¾ÍÊÇ ECMAScript ÔÊÐíʹÓÃÄÚ²¿º¯Êý£­£­¼´º¯Êý¶¨ÒåºÍº¯Êý±í´ïʽλÓÚÁíÒ»¸öº¯ÊýµÄº¯ÊýÌåÄÚ¡£¶øÇÒ£¬ÕâЩÄÚ²¿º¯Êý¿ÉÒÔ·ÃÎÊËüÃÇËùÔÚµÄÍⲿº¯ÊýÖÐÉùÃ÷µÄËùÓоֲ¿±äÁ¿¡¢²ÎÊýºÍÉùÃ÷µÄÆäËûÄÚ²¿º¯Êý¡£µ±ÆäÖÐÒ»¸öÕâÑùµÄÄÚ²¿º¯ÊýÔÚ°üº¬ËüÃǵÄÍⲿº¯ÊýÖ®Íâ±»µ÷ÓÃʱ£¬¾Í»áÐγɱհü¡£Ò²¾ÍÊÇ˵£¬ÄÚ²¿º¯Êý»áÔÚÍⲿº¯Êý·µ»Øºó±»Ö´ÐС£¶øµ±Õâ¸öÄÚ²¿º¯ÊýÖ´ÐÐʱ£¬ËüÈÔÈ»±ØÐè·ÃÎÊÆäÍⲿº¯ÊýµÄ¾Ö²¿±äÁ¿¡¢²ÎÊýÒÔ¼°ÆäËûÄÚ²¿º¯Êý¡£ÕâЩ¾Ö²¿±äÁ¿¡¢²ÎÊýºÍº¯ÊýÉùÃ÷£¨×î³õʱ£©µÄÖµÊÇÍⲿº¯Êý·µ»ØʱµÄÖµ£¬µ«Ò²»áÊܵ½ÄÚ²¿º¯ÊýµÄÓ°Ïì¡£
Òź¶µÄÊÇ£¬ÒªÊʵ±µØÀí½â±Õ°ü¾Í±ØÐëÀí½â±Õ°ü±³ºóÔËÐеĻúÖÆ£¬ÒÔ¼°Ðí¶àÏà¹ØµÄ¼¼Êõϸ½Ú¡£ËäÈ»±¾ÎĵÄÇ°°ë²¿·Ö²¢Ã»ÓÐÉæ¼° ECMA 262 ¹æ·¶Ö¸¶¨µÄijЩËã·¨£¬µ«ÈÔÈ»ÓÐÐí¶àÎÞ·¨»Ø±Ü»ò¼ò»¯µÄÄÚÈÝ¡£¶ÔÓÚ¸ö±ðÊìϤ¶ÔÏóÊôÐÔÃû½âÎöµÄÈËÀ´Ëµ£¬¿ÉÒÔÌø¹ýÏà¹ØµÄÄÚÈÝ£¬µ«Êdzý·ÇÄã¶Ô±Õ°üÒ²·Ç³£ÊìϤ£¬·ñÔò×îºÃÊDz»ÒªÌø¹ýÏÂÃ漸½Ú¡£
¶ÔÏóÊôÐÔÃû½âÎö
ECMAScript ÈÏ¿ÉÁ½Àà¶ÔÏó£ºÔ­Éú£¨Native£©¶ÔÏóºÍËÞÖ÷£¨Host£©¶ÔÏó£¬ÆäÖÐËÞÖ÷¶ÔÏó°üº¬Ò»¸ö±»³ÆΪÄÚÖöÔÏóµÄÔ­Éú¶ÔÏóµÄ×ÓÀࣨECMA 262 3rd Ed Section 4.3£©¡£Ô­Éú¶ÔÏóÊôÓÚÓïÑÔ£¬¶øËÞÖ÷¶ÔÏóÓÉ»·¾³Ìṩ£¬±ÈÈç˵¿ÉÄÜÊÇÎĵµ¶ÔÏó¡¢DOM µÈÀàËƵĶÔÏó¡£
Ô­Éú¶ÔÏó¾ßÓÐËÉÉ¢ºÍ¶¯Ì¬µÄÃüÃûÊôÐÔ£¨¶ÔÓÚijЩʵÏÖµÄÄÚÖ


Ïà¹ØÎĵµ£º

×î½ü×Ô¼ºÔÚдjavascript/html/cssµÄÊ÷¿Ø¼þ

    Íê³ÉÒÔϲ¿·Ö£º
    1. Ê÷¿ÉÒÔ½ÓÊÜsingleXml¸ñʽºÍjsonÒÔ¼°jsonarray¸ñʽµÄÊý¾Ý£»
    2. ¸´Ñ¡¿ò¹´Ñ¡ºÍÕÛµþ×Ó½ÚµãµÄÂß¼­ÓÃdivǶÌ×À´ÊµÏÖ,ЧÂʸü¸ß;²¢ÌṩÁË¿ìËÙ»­Ê÷µÄ·½·¨;(´æÔÚbug:¿ìËÙ»­Ê÷ЧÂʲ¢²»¸ß,divǶÌ×ÓÐÎÊÌâ);
    3.Ôö¼ÓÊ÷µÄÉî¶È this.depth ......

JavaScript¾ÍÕâô»ØÊ (JS»ù´¡ÖªÊ¶ÕûÀí)

JavaScript¾ÍÕâô»ØÊ (JS»ù´¡ÖªÊ¶ÕûÀí)
1 ´´½¨½Å±¾¿é  
1: <script language=”JavaScript”>  
2: JavaScript code goes
here  
3: </script>
2 Òþ²Ø½Å±¾´úÂë  
1: <script language=”JavaScript”>  
2: <!&ndas ......

javascript cookies ´æ¡¢È¡¡¢É¾³ýʵÀý

<script>
//дcookiesº¯Êý ×÷ÕߣºµÔÕñ¿­
function SetCookie(name,value)//Á½¸ö²ÎÊý£¬Ò»¸öÊÇcookieµÄÃû×Ó£¬Ò»¸öÊÇÖµ
{
    var Days = 30; //´Ë cookie ½«±»±£´æ 30 Ìì
    var exp  = new Date();    //new Date("December 31, 9998");
    ......

JavaScriptÖÐµÄ escape,encodeURI,encodeURIComponent


js¶ÔÎÄ×Ö½øÐбàÂëÉæ¼°3¸öº¯Êý£ºescape,encodeURI,encodeURIComponent£¬ÏàÓ¦3¸ö½âÂ뺯Êý£ºunescape,decodeURI,decodeURIComponent
1¡¢   ´«µÝ²ÎÊýʱÐèҪʹÓÃencodeURIComponent£¬ÕâÑù×éºÏµÄurl²Å²»»á±»#µÈÌØÊâ×Ö·û½Ø¶Ï¡£               ......

ÉîÈëÀí½âJavaScript±Õ°ü£¨closure£©

×î½üÔÚÍøÉϲéÔÄÁ˲»ÉÙJavascript±Õ°ü(closure)Ïà¹ØµÄ×ÊÁÏ£¬Ð´µÄ´ó¶àÊǷdz£µÄѧÊõºÍרҵ¡£¶ÔÓÚ³õѧÕßÀ´Ëµ±ð˵Àí½â±Õ°üÁË£¬¾ÍÁ¬ÎÄ×ÖÐðÊö¶¼ºÜÄÑ¿´¶®¡£×«Ð´´ËÎĵÄÄ¿µÄ¾ÍÊÇÓÃ×îͨË×µÄÎÄ×Ö½Ò¿ªJavascript±Õ°üµÄÕæʵÃæÄ¿¡£
Ò»¡¢Ê²Ã´ÊDZհü£¿
“¹Ù·½”µÄ½âÊÍÊÇ£ºËùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨Á ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ