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

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

Nested Members  ǶÌ׳ÉÔ±
    Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is encountered. Figure 2-12 shows the relationship between object member depth and time to access.
    ÓÉÓÚ¶ÔÏó³ÉÔ±¿ÉÄÜ°üº¬ÆäËü³ÉÔ±£¬ÀýÈ粻̫³£¼ûµÄд·¨window.location.hrefÕâÖÖģʽ¡£Ã¿Óöµ½Ò»¸öµãºÅ£¬JavaScriptÒýÇæ¾ÍÒªÔÚ¶ÔÏó³ÉÔ±ÉÏÖ´ÐÐÒ»´Î½âÎö¹ý³Ì¡£Í¼2-12ÏÔʾ³ö¶ÔÏó³ÉÔ±Éî¶ÈÓë·ÃÎÊʱ¼äµÄ¹Øϵ¡£
Figure 2-12. Access time related to property depth
ͼ2-12  ·ÃÎÊʱ¼äÓëÊôÐÔÉî¶ÈµÄ¹Øϵ
    It should come as no surprise, then, that the deeper the nested member, the slower the data is accessed. Evaluating location.href is always faster than window.location.href, which is faster than window.location.href.toString(). If these properties aren't on the object instances, then member resolution will take longer as the prototype chain is searched at each point.
    ½á¹û²¢²»Ææ¹Ö£¬³ÉԱǶÌ×Ô½É·ÃÎÊËÙ¶ÈÔ½Âý¡£location.href×ÜÊÇ¿ìÓÚwindow.location.href£¬¶øºóÕßÒ²Òª±Èwindow.location.href.toString()¸ü¿ì¡£Èç¹ûÕâЩÊôÐÔ²»ÊǶÔÏóµÄʵÀýÊôÐÔ£¬ÄÇô³ÉÔ±½âÎö»¹ÒªÔÚÿ¸öµãÉÏËÑË÷Ô­ÐÎÁ´£¬Õ⽫ÐèÒª¸ü³¤Ê±¼ä¡£
Caching Object Member Values  »º´æ¶ÔÏó³ÉÔ±µÄÖµ
    With all of the performance issues related to object members, it's easy to believe that they should be avoided whenever possible. To be more accurate, you should be careful to use object member only when necessary. For instance, there's no reason to read the value of an object member more than once in a single function:
    ÓÉÓÚËùÓÐÕâЩÐÔÄÜÎÊÌâÓë¶ÔÏó³ÉÔ±Óйأ¬ËùÒÔÈç¹û¿ÉÄܵĻ°Çë±ÜÃâʹÓÃËüÃÇ¡£¸üÈ·ÇеØ˵£¬ÄãÓ¦µ±Ð¡Ðĵأ¬Ö»ÔÚ±ØÒªÇé¿öÏÂʹÓöÔÏó³ÉÔ±¡£ÀýÈ磬ûÓÐÀíÓÉÔÚÒ»¸öº¯ÊýÖжà´Î¶Áȡͬһ¸ö¶ÔÏó³ÉÔ±µÄÖµ£º
function hasEitherClass(element, className1, className2){
  return element.c


Ïà¹ØÎĵµ£º

JavascriptÃæÏò¶ÔÏó±à³Ì£¨¶þ£©£º¼Ì³Ð


ZT:http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html
ÉÏÒ»´ÎµÄÎÄÕ£¬Ö÷Òª½éÉÜÁËÈçºÎ"·â×°"Êý¾ÝºÍ·½·¨£¬´ÓÔ­ÐͶÔÏóÉú³ÉʵÀý¡£
½ñÌìÒª½éÉܵÄÊÇ£¬¶à¸öÔ­ÐͶÔÏóÖ®¼äÈçºÎ"¼Ì³Ð"¡£
±ÈÈ磬ÏÖÔÚÓÐÒ»¸ö"¶¯Îï"¶ÔÏó£¬
¡¡¡¡function Animal(){
¡¡¡¡¡¡¡¡this.species = "¶¯Îï";
¡¡¡¡}
»¹ÓÐ ......

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


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

JavaScriptµÄBASE64

**
* ÎÒÔÚÍøÉÏ¿´µ½¹ýºÜ¶àBASE64µÄJavaScriptËã·¨£¬¶¼¾õµÃ²»ÂúÒ⣬ÓÚÊÇ×Ô¼ºÐ´ÁËÒ»¸ö£¬ÔÚÕâÀï·ÖÏíһϡ£
* ÎҵĴúÂëÔÚÖÊÁ¿µÄЧÂʶ¼½Ï¸ß£¬Ã»ÓÐһЩÈßÓàµÄ²Ù×÷¡£×ÜÌåÀ´½²ÎÒ¾õµÃ·Ç³£²»´í¡£
* Èç¹û´ó¼ÒÓÐʲô²»¶®µÄµØ·½¿ÉÒÔÎÊÎÒ¡£
*/
var BASE64={
    /**
     * ´Ë±äÁ¿Îª±àÂëµÄ ......

[¶ÁÊé±Ê¼Ç][JavaScript¸ß¼¶³ÌÐòÉè¼Æ]

µÚ¶þÕ£ºECMAScript»ù´¡
1.µ±º¯ÊýÎÞÃ÷È··µ»Øֵʱ£¬·µ»ØµÄÒ²ÊÇÖµundefined
  function testFunc(){}
  alert(testFunc()==undefined);
2.typeof(null)=='object' //true,null¿ÉÒÔ½âÊÍΪ¶ÔÏóռλ·û
3.undefined ÊÇÉùÃ÷Á˱äÁ¿µ«Î´¶ÔÆä³õʼ»¯Ê±¸³Óè¸Ã±äÁ¿µÄÖµ£¬nullÔòÓÃÓÚ±íʾÉÐδ´æÔڵĶÔÏó¡£
  alert(nu ......

[·­Òë]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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ