[·Òë]High Performance JavaScript(019)
µÚÁùÕ Responsive Interfaces ÏìÓ¦½Ó¿Ú
There's nothing more frustrating than clicking something on a web page and having nothing happen. This problem goes back to the origin of transactional web applications and resulted in the now-ubiquitous "please click only once" message that accompanies most form submissions. A user's natural inclination is to repeat any action that doesn't result in an obvious change, and so ensuring responsiveness in web applications is an important performance concern.
ûÓÐʲô±Èµã»÷Ò³ÃæÉϵĶ«Î÷ȴʲôҲû·¢Éú¸üÁîÈ˸е½´ìÕÛÁË¡£Õâ¸öÎÊÌâÓֻص½ÁËÔʼÍøÒ³½»»¥³ÌÐòºÍÏÖÔÚÒÑÎÞ´¦²»ÔÚµÄÌá½»±íµ¥Ê±µ¯³öµÄ“ÇëÎðÖظ´Ìá½»”ÏûÏ¢ÉÏÃæ¡£Óû§×ÔÈ»ÇãÏòÓÚÖظ´³¢ÊÔÕâЩ²»·¢ÉúÃ÷ÏԱ仯µÄ¶¯×÷£¬ËùÒÔÈ·±£ÍøÒ³Ó¦ÓóÌÐòµÄÏìÓ¦ËÙ¶ÈÒ²ÊÇÒ»¸öÖØÒªµÄÐÔÄܹØ×¢µã¡£
Chapter 1 introduced the browser UI thread concept. As a recap, most browsers have a single process that is shared between JavaScript execution and user interface updates. Only one of these operations can be performed at a time, meaning that the user interface cannot respond to input while JavaScript code is executed and vice versa. The user interface effectively becomes "locked" when JavaScript is executing; managing how long your JavaScript takes to execute is important to the perceived performance of a web application.
µÚÒ»½Ú½éÉÜÁËä¯ÀÀÆ÷UIÏ̸߳ÅÄî¡£×ܵÄÀ´Ëµ£¬´ó¶àÊýä¯ÀÀÆ÷ÓÐÒ»¸öµ¥¶ÀµÄ´¦Àí½ø³Ì£¬ËüÓÉÁ½¸öÈÎÎñËù¹²Ïí£ºJavaScriptÈÎÎñºÍÓû§½çÃæ¸üÐÂÈÎÎñ¡£Ã¿¸öʱ¿ÌÖ»ÓÐÆäÖеÄÒ»¸ö²Ù×÷µÃÒÔÖ´ÐУ¬Ò²¾ÍÊÇ˵µ±JavaScript´úÂëÔËÐÐʱÓû§½çÃæ²»ÄܶÔÊäÈë²úÉú·´Ó¦£¬·´Ö®ÒàÈ»¡£»òÕß˵£¬µ±JavaScriptÔËÐÐʱ£¬Óû§½çÃæ¾Í±»“Ëø¶¨”ÁË¡£¹ÜÀíºÃJavaScriptÔËÐÐʱ¼ä¶ÔÍøÒ³Ó¦ÓõÄÐÔÄܺÜÖØÒª¡£
The Browser UI Thread ä¯ÀÀÆ÷UIÏß³Ì
The process shared by JavaScript and user interface updates is frequently referred to as the browser UI thread (though the term "thread" is not necessarily accurate for all browsers). The UI thread works on a sim
Ïà¹ØÎĵµ£º
Ò³ÃæÌá½»Êý¾ÝÒ»°ãÓÐÁ½ÖÖ·½·¨£ºget,post¡£post¾ÍÊÇËùνµÄformÌá½»£¬Ê¹ÓÃÊÓͼ£»getÊÇͨ¹ýurlÌá½»¡£
Get·½·¨Ò»°ãÓúǫ́´úÂ루Èçasp,asp.net£©»ñµÃ²ÎÊý£¬´úÂëºÜ¼òµ¥£ºRequest.QueryString["id"];¼´¿É»ñÈ¡¡£
ÓÐЩʱºòÐèÒªÖ±½ÓÔÚǰ̨»ñÈ¡url²ÎÊý£¬ÒªÓõ½javascript£¬jsûÓÐÖ±½Ó»ñÈ¡url²ÎÊýµÄ·½·¨£¬ÄÇô£¬ÎÒÃÇÈçºÎͨ¹ýjs ......
JavaScriptʼþ´óÈ«
click() ¶ÔÏó.click() ʹ¶ÔÏó±»µã»÷¡£
closed ¶ÔÏó.closed ¶ÔÏó´°¿ÚÊÇ·ñÒѹرÕtrue/false
clearTimeout(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetTimeout¶ÔÏó
clearInterval(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetInterval¶ÔÏó
confirm("ÌáʾÐÅÏ¢") µ¯³öÈ·ÈÏ¿ò£¬È·¶¨·µ»ØtrueÈ¡Ïû·µ»Øfalse
cursor:Ñùʽ ¸ü¸ÄÊó±êÑùÊ ......
typeof ÊÇJavaScriptµÄÔËËã·û
——·µ»ØÒ»¸öÓÃÀ´±íʾ±í´ïʽµÄÊý¾ÝÀàÐ͵Ä×Ö·û´®
typeof[(] expression [)] //typeofÓï·¨ÖеÄÔ²À¨ºÅÊÇ¿ÉÑ¡Ïî
typeof ÔËËã·û@import url(../html-vss/msdnie4a.css);
typeof
ÔËËã·û°ÑÀàÐÍÐÅÏ¢µ±×÷×Ö·û´®·µ»Ø¡£typeof
·µ»ØÖµÓÐÁ ......
A Note on Benchmarking ²âÊÔ»ù׼˵Ã÷
Because a regex's performance can be wildly different depending on the text it's applied to, there's no straightforward way to benchmark regexes against each other. For the best result, you need to benchmark your regexes on test strings o ......