[·Òë]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
Ïà¹ØÎĵµ£º
±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔÀ´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷ÔÒò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......
ÎÒ»¹ÊDzËÄñ£¬Çë´ó¼Ò¶àÖ¸½Ì£¡
Ò³ÃæÒ»£º
<html>
<head>
<title> Ò³Ãæ´«ÖµÒ» </title>
<script>
function funShow()
{
var arr=new Array(6);
var arrs = showModalDialog("Ò³ ......
ZT:http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html
ÉÏÒ»´ÎµÄÎÄÕ£¬Ö÷Òª½éÉÜÁËÈçºÎ"·â×°"Êý¾ÝºÍ·½·¨£¬´ÓÔÐͶÔÏóÉú³ÉʵÀý¡£
½ñÌìÒª½éÉܵÄÊÇ£¬¶à¸öÔÐͶÔÏóÖ®¼äÈçºÎ"¼Ì³Ð"¡£
±ÈÈ磬ÏÖÔÚÓÐÒ»¸ö"¶¯Îï"¶ÔÏó£¬
¡¡¡¡function Animal(){
¡¡¡¡¡¡¡¡this.species = "¶¯Îï";
¡¡¡¡}
»¹ÓÐ ......
1.DOMÊÇÕë¶ÔXMLµÄ»ùÓÚÊ÷µÄAPI¡£Ê¹ÓÃDOM£¬Ö»Ðè½âÎö´úÂëÒ»´ÎÀ´´´½¨Ò»¸öÊ÷µÄÄ£ÐÍ¡£ÔÚÕâ¸ö³õʼ½âÎö¹ý³ÌÖ®ºó£¬XMLÒѾÍêȫͨ¹ýDOMÄ£ÐͱíÏÖ³öÀ´£¬Í¬Ê±Ò²²»ÔÙÐèÒªÔʼµÄ´úÂë¡£
NB
£ºDOMÊÇÓïÑÔÎ޹صÄAPI£¬Ëü²¢²»ÓëJava¡¢JavaScript»òÆäËûÓïÑ԰󶨡£ ......
µÚ¶þÕ£ºECMAScript»ù´¡
1.µ±º¯ÊýÎÞÃ÷È··µ»Øֵʱ£¬·µ»ØµÄÒ²ÊÇÖµundefined
function testFunc(){}
alert(testFunc()==undefined);
2.typeof(null)=='object' //true,null¿ÉÒÔ½âÊÍΪ¶ÔÏóռλ·û
3.undefined ÊÇÉùÃ÷Á˱äÁ¿µ«Î´¶ÔÆä³õʼ»¯Ê±¸³Óè¸Ã±äÁ¿µÄÖµ£¬nullÔòÓÃÓÚ±íʾÉÐδ´æÔڵĶÔÏó¡£
alert(nu ......