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

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

Identifier Resolution Performance  ±êʶ·ûʶ±ðÐÔÄÜ
    Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for both reads and writes. Consequently, local variables are always the fastest to access inside of a function, whereas global variables will generally be the slowest (optimizing JavaScript engines are capable of tuning this in certain situations). Keep in mind that global variables always exist in the last variable object of the execution context's scope chain, so they are always the furthest away to resolve. Figures 2-4 and 2-5 show the speed of identifier resolution based on their depth in the scope chain. A depth of 1 indicates a local variable.
    ±êʶ·ûʶ±ð²»ÊÇÃâ·ÑµÄ£¬ÊÂʵÉÏûÓÐÄÄÖÖµçÄÔ²Ù×÷¿ÉÒÔ²»²úÉúÐÔÄÜ¿ªÏú¡£ÔÚÔËÐÐÆÚÉÏÏÂÎĵÄ×÷ÓÃÓòÁ´ÖУ¬Ò»¸ö±êʶ·ûËù´¦µÄλÖÃÔ½ÉËüµÄ¶ÁдËٶȾÍÔ½Âý¡£ËùÒÔ£¬º¯ÊýÖоֲ¿±äÁ¿µÄ·ÃÎÊËÙ¶È×ÜÊÇ×î¿ìµÄ£¬¶øÈ«¾Ö±äÁ¿Í¨³£ÊÇ×îÂýµÄ£¨ÓÅ»¯µÄJavaScriptÒýÇæÔÚijЩÇé¿öÏ¿ÉÒԸıäÕâÖÖ×´¿ö£©¡£Çë¼Çס£¬È«¾Ö±äÁ¿×ÜÊÇ´¦ÓÚÔËÐÐÆÚÉÏÏÂÎÄ×÷ÓÃÓòÁ´µÄ×îºóÒ»¸öλÖã¬ËùÒÔ×ÜÊÇ×îÔ¶²ÅÄÜ´¥¼°µÄ¡£Í¼2-4ºÍ2-5ÏÔʾÁË×÷ÓÃÓòÁ´Éϲ»Í¬Éî¶È±êʶ·ûµÄʶ±ðËٶȣ¬Éî¶ÈΪ1±íʾһ¸ö¾Ö²¿±äÁ¿¡£
Figure 2-4. Identifier resolution for write operations
ͼ2-4  д²Ù×÷µÄ±êʶ·ûʶ±ðËÙ¶È
Figure 2-5. Identifier resolution for read operations
ͼ2-5  ¶Á²Ù×÷µÄ±êʶ·ûʶ±ðËÙ¶È
    The general trend across all browsers is that the deeper into the scope chain an identifier exists, the slower it will be read from or written to. Browsers with optimizing JavaScript engines, such as Chrome and Safari 4, don't have this sort of performance penalty for accessing out-of-scope identifiers, whereas Internet Explorer, Safari 3.2, and others show a more drastic effect. It's worth noting that earlier browsers, such as Internet Explorer 6 and Firefox 2, had incredibly steep slopes and would no


Ïà¹ØÎĵµ£º

JavaScriptѧϰ±Ê¼Ç£¨Î壩

1.ÔÚHTMLÖÐʹÓÃ<script>ÔªËØÒýÈëJavaScript¡£
   ¸ÃÔªËØÓÐÁ½¸öÊôÐÔ£¬languageÉùÃ÷ҪʹÓõĽű¾ÓïÑÔ£¬srcÊôÐÔÊÇ¿ÉÑ¡µÄ£¬ÓÃÓÚÒýÓÃÍⲿJavaScriptÎļþ¡£
   NB
£ºÏÖÔÚ´ó¶àʹÓÃtypeÊôÐÔ£¨type=“text/javascript”£©Ìæ´úlanguageÊôÐÔ£¬ÒÔ±ã¸üºÃµØÖ§³ÖXHTML£¨¿ÉÀ©Õ¹HTML£©¡£
2.Ò»°ãÈÏΪ ......

JavascriptÃæÏò¶ÔÏó±à³Ì£¨Èý£©£º·Çº¯Êý¶ÔÏóµÄ¼Ì³Ð


×òÌ죬ÎÒ±¾À´´òË㣬°ÑÕâ¸ö»°Ìâ½áÊøÁË¡£
µ«ÊÇ£¬Ð´µ½Ò»°ëµÄʱºò£¬ÎÒͻȻÒâʶµ½£¬JavascriptµÄ¼Ì³ÐÓÐÁ½ÖÖ¡£Ò»ÖÖÊÇ»ùÓÚ"º¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬Ò²¾ÍÊÇÒ»¸öfunctionÈ¥¼Ì³ÐÁíÍâÒ»¸öfunction£¬Õâ¸öÎÒÒѾ­ÔÚ×òÌì½éÉܹýÁË¡£
ÁíÒ»ÖÖÔòÊÇ»ùÓÚ"·Çº¯Êý¶ÔÏó"µÄ¼Ì³Ð£¬²»Éæ¼°function¡£ËüµÄ×ö·¨ÓëÇ°Ò»ÖÖÇé¿öÍêÈ«²»Í¬¡£
Ò»¡¢Ê²Ã´ÊÇ"·Çº¯Êý¶ÔÏ ......

Èç¹ûÔÚCHtmlDialogÖе÷ÓÃJavascriptº¯Êý

// µ÷ÓÃÒ³ÃæµÄˢз½·¨
     IHTMLWindow2* pWindow;
     IHTMLDocument2*   pDocument; 
     HRESULT hr = GetDHtmlDocument(&pDocument);  
     hr = pDocument->get_pa ......

JavaScript:history.go() µÄÃîÓÃ(ת)

  ÔÚWeb¿ª·¢ÖУ¬»áÓöµ½´ÓÒ»Ò³£¨¸¸Ò³£©µ¼ÏòÁíÒ»Ò³£¨×ÓÒ³£©£¬²¢ÇÒÒªÇó“·µ»Ø”¸¸Ò³µÄÇé¿ö£¬ÔÚÕâÀïÈç¹ûÓÃASP.NETÌṩµÄ Response.Redirect()·½·¨£¬ÍùÍù²»»á´ïµ½ÀíÏëµÄЧ¹û£¬ÀýÈ磺·µ»Øºó£¬ÖØмÓÔØÁËÒ³Ã棬ÎÞ·¨±£´æµ¼Ïò×ÓҳǰµÄ״̬£¬µÈµÈ£¬ÔÚÕâÀïÎҾͽéÉÜ Ò»ÏÂÈçºÎʹÓÃJavaScriptÖÐhistory.go()º¯ÊýÀ´ÊµÏÖ·µ»Ø ......

javascript location.reload()

¹¦ÄÜ£º
ÖØмÓÔØÎĵµ¡£
Óï·¨£º
location.reload(force)
²ÎÊý£º
force£º¿ÉÑ¡²ÎÊý£¬ÊÇÒ»¸ö²¼¶ûÖµ¡£
      Èç¹ûÊ¡ÂÔ²ÎÊý£¬»òÕß²ÎÊýÊÇfalse£¬Ëü¾Í»áÓÃHTTPÍ·If-Modified-SinceÀ´¼ì²â·þÎñÆ÷ÉϵÄÎĵµÊÇ·ñÒѸı䡣Èç¹ûÎĵµÒѸÄ
±ä£¬reload()»áÔÙ´ÎÏÂÔظÃÎĵµ¡£Èç¹ûÎĵµÎ´¸Ä±ä£¬Ôò¸Ã·½·¨½«´Ó»º´æÖÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ