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

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

µÚËÄÕ  Algorithms and Flow Control  Ëã·¨ºÍÁ÷³Ì¿ØÖÆ
    The overall structure of your code is one of the main determinants as to how fast it will execute. Having a very small amount of code doesn't necessarily mean that it will run quickly, and having a large amount of code doesn't necessarily mean that it will run slowly. A lot of the performance impact is directly related to how the code has been organized and how you're attempting to solve a given problem.
    ´úÂëÕûÌå½á¹¹ÊÇÖ´ÐÐËٶȵľö¶¨ÒòËØÖ®Ò»¡£´úÂëÁ¿ÉÙ²»Ò»¶¨ÔËÐÐËٶȿ죬´úÂëÁ¿¶àÒ²²»Ò»¶¨ÔËÐÐËÙ¶ÈÂý¡£ÐÔÄÜËðʧÓë´úÂë×éÖ¯·½Ê½ºÍ¾ßÌåÎÊÌâ½â¾ö°ì·¨Ö±½ÓÏà¹Ø¡£
    The techniques in this chapter aren't necessarily unique to JavaScript and are often taught as performance optimizations for other languages. There are some deviations from advice given for other languages, though, as there are many more JavaScript engines to deal with and their quirks need to be considered, but all of the techniques are based on prevailing computer science knowledge.
    ±¾Õ¼¼Êõ²»½öÊÊÓÃÓÚJavaScriptÒ²ÊÊÓÃÓÚÆäËûÓïÑÔµÄÐÔÄÜÓÅ»¯¡£»¹ÓÐһЩΪÆäËûÓïÑÔÌṩµÄ½¨Ò飬»¹Òª´¦Àí¶àÖÖJavaScriptÒýÇæ²¢¿¼ÂÇËüÃǵIJîÒ죬µ«ÕâЩ¼¼Êõ¶¼ÒÔµ±Ç°¼ÆËã»ú¿Æѧ֪ʶΪ»ù´¡¡£
Loops  Ñ­»·
    In most programming languages, the majority of code execution time is spent within loops. Looping over a series of values is one of the most frequently used patterns in programming and as such is also one of the areas where efforts to improve performance must be focused. Understanding the performance impact of loops in JavaScript is especially important, as infinite or long-running loops severely impact the overall user experience.
    ÔÚ´ó¶àÊý±à³ÌÓïÑÔÖУ¬´úÂëÖ´ÐÐʱ¼ä¶àÊýÔÚÑ­»·Öжȹý¡£ÔÚһϵÁбà³ÌģʽÖУ¬Ñ­»·ÊÇ×î³£ÓõÄģʽ֮һ£¬Òò´ËÒ²ÊÇÌá¸ßÐÔÄܱØÐë¹Ø×¢µÄµØÇøÖ®Ò»¡£Àí½âJavaScriptÖÐÑ­»·¶ÔÐÔÄܵÄÓ°ÏìÖÁ¹ØÖØÒª£¬ÒòΪËÀÑ­»·»òÕß³¤Ê±¼äÔËÐеÄÑ­»·»áÑÏÖØÓ°ÏìÓû§ÌåÑé¡£
Types of Loops  Ñ­»·µÄÀàÐ


Ïà¹ØÎĵµ£º

javascriptЧÂʾ­Ñé̸(Ò»)

±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔ­À´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾­Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾­¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷Ô­Òò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......

ͨ¹ýjavascript»ñµÃurl²ÎÊý

Ò³ÃæÌá½»Êý¾ÝÒ»°ãÓÐÁ½ÖÖ·½·¨£ºget,post¡£post¾ÍÊÇËùνµÄformÌá½»£¬Ê¹ÓÃÊÓͼ£»getÊÇͨ¹ýurlÌá½»¡£
Get·½·¨Ò»°ãÓúǫ́´úÂ루Èçasp,asp.net£©»ñµÃ²ÎÊý£¬´úÂëºÜ¼òµ¥£ºRequest.QueryString["id"];¼´¿É»ñÈ¡¡£ 
ÓÐЩʱºòÐèÒªÖ±½ÓÔÚǰ̨»ñÈ¡url²ÎÊý£¬ÒªÓõ½javascript£¬jsûÓÐÖ±½Ó»ñÈ¡url²ÎÊýµÄ·½·¨£¬ÄÇô£¬ÎÒÃÇÈçºÎͨ¹ýjs ......

javascript¼Ì³Ð·½Ê½Ö®¶þ

2¡¢Ô­ÐÍ·½Ê½Ð´À࣬ԭÐÍ·½Ê½¼Ì³Ð
core js×ÔÉíµÄ¶ÔÏóϵͳ¾ÍÊDzÉÓÃÔ­ÐÍ·½Ê½(prototype based)¼Ì³ÐµÄ¡£»òÕß˵core
jsûÓвÉÓó£¼ûµÄÀà¼Ì³Ð(class
based)ϵͳ£¬¶øÊÇʹÓÃÔ­Ðͼ̳ÐÀ´ÊµÏÖ×Ô¼ºµÄ¶ÔÏóϵͳ¡£¹¤×÷ÖÐÎÒÃÇÒ²¿ÉÒÔÓÃÔ­ÐÍ·½Ê½À´ÊµÏּ̳У¬´úÂ븴ÓÃÒÔ¹¹½¨×Ô¼ºµÄ¹¦ÄÜÄ£¿é¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
*
*/
functio ......

javascript¼Ì³Ð·½Ê½Ö®Èý

3¡¢×éºÏ¹¹Ô캯Êý/Ô­ÐÍ·½Ê½Ð´À࣬²ÉÓÃÇ°ÃæÖÖ·½Ê½¼Ì³Ð
ÕâÖÖ·½Ê½¸¸À࣬×ÓÀàµÄÊôÐÔ¶¼¹ÒÔÚ¹¹Ô캯ÊýÀ·½·¨¶¼¹ÒÔÚÔ­ÐÍÉÏ¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
*/
function Polygon(sides) {
this.sides = sides;
}
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
* Triangle Èý½ÇÐÎ
* @param {Object} b ......

Javascript±Õ°ü(Closure)

ClosureÖÐÎÄ·­ÒëΪ±Õ°ü.×ÖÃæÉÏÀ´Àí½â¾ÍÊÇ"·â±ÕµÄ°ü".(ÕâÊÇÒ»¾ä·Ï»°)
±Õ°üÊÇʲô?
ÊéÃæ½âÊÍΪ:
Ëùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
ÎÒÈÏΪ±Õ°ü¾ÍÊÇÄܹ»¶Á/дº¯ÊýÄÚ²¿µÄijЩ±äÁ¿µÄ×Óº¯Êý,²¢½«ÕâЩ±äÁ¿±£´æ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ