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

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

Yielding with Timers  Óö¨Ê±Æ÷Èóöʱ¼äƬ
    Despite your best efforts, there will be times when a JavaScript task cannot be completed in 100 milliseconds or less because of its complexity. In these cases, it's ideal to yield control of the UI thread so that UI updates may occur. Yielding control means stopping JavaScript execution and giving the UI a chance to update itself before continuing to execute the JavaScript. This is where JavaScript timers come into the picture.
    ¾¡¹ÜÄ㾡ÁË×î´óŬÁ¦£¬»¹ÊÇÓÐһЩJavaScriptÈÎÎñÒòΪ¸´ÔÓÐÔÔ­Òò²»ÄÜÔÚ100ºÁÃë»ò¸üÉÙʱ¼äÄÚÍê³É¡£ÕâÖÖÇé¿öÏ£¬ÀíÏë·½·¨ÊÇÈóö¶ÔUIÏ̵߳ĿØÖÆ£¬Ê¹UI¸üпÉÒÔ½øÐС£Èóö¿ØÖÆÒâζ×ÅÍ£Ö¹JavaScriptÔËÐУ¬¸øUIÏ̻߳ú»á½øÐиüУ¬È»ºóÔÙ¼ÌÐøÔËÐÐJavaScript¡£ÓÚÊÇJavaScript¶¨Ê±Æ÷½øÈëÁËÎÒÃǵÄÊÓÒ°¡£
Timer Basics  ¶¨Ê±Æ÷»ù´¡
    Timers are created in JavaScript using either setTimeout() or setInterval(), and both accept the same arguments: a function to execute and the amount of time to wait (in milliseconds) before executing it. The setTimeout() function creates a timer that executes just once, whereas the setInterval() function creates a timer that repeats periodically.
    ÔÚJavaScriptÖÐʹÓÃsetTimeout()»òsetInterval()´´½¨¶¨Ê±Æ÷£¬Á½¸öº¯Êý¶¼½ÓÊÕÒ»ÑùµÄ²ÎÊý£ºÒ»¸öÒªÖ´Ðеĺ¯Êý£¬ºÍÒ»¸öÔËÐÐËü֮ǰµÄµÈ´ýʱ¼ä£¨µ¥Î»ºÁÃ룩¡£setTimeout()º¯Êý´´½¨Ò»¸ö¶¨Ê±Æ÷Ö»ÔËÐÐÒ»´Î£¬¶øsetInterval()º¯Êý´´½¨Ò»¸öÖÜÆÚÐÔÖØ¸´ÔËÐеĶ¨Ê±Æ÷¡£
    The way that timers interact with the UI thread is helpful for breaking up long-running scripts into shorter segments. Calling setTimeout() or setInterval() tells the JavaScript engine to wait a certain amount of time and then add a JavaScript task to the UI queue. For example:
    ¶¨Ê±Æ÷ÓëUIÏ߳̽»»¥µÄ·½Ê½ÓÐÖúÓڷֽⳤÔËÐнű¾³ÉΪ½Ï¶ÌµÄƬ¶Ï¡£µ÷ÓÃsetTimeout()»òsetInterval()¸æËßJavaScriptÒýÇæµÈ´ýÒ»¶¨Ê±¼äÈ»ºó½«JavaScriptÈÎÎñÌí¼Óµ½UI¶ÓÁÐÖС£ÀýÈ磺
function greeting(){
  alert("Hello world!");
}
setTimeout(gree


Ïà¹ØÎĵµ£º

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

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

javaScript¹Ø±Õä¯ÀÀÆ÷ (²»µ¯³öÌáʾ¿ò)

£¼script language="javaScript"£¾
function closeWindow()
{
¡¡window.opener = null;
¡¡window.open(' ', '_self', ' ');
¡¡window.close();
}
£¼/script£¾
£¼input type='button' value='¹Ø±Õ´°¿Ú' onClick="closeWindow()"£¾
»ò
£¼input type="button" value="¹ ......

JavaScript»ù´¡ÖªÊ¶2

ÍæPHP¡¢Delphi¡¢Java»ù±¾É϶¼ÓжÔÏó£¬Ï°¹ßÕâÖÖ˼·ºóÉÏÊÖÈκÎÓïÑÔ¶¼Ïë¿¿OO˼·£¬Õâ¾ø²»ÊÇÔÚ¸Ïʱ÷Ö£¬¶øÊǰÑÏà¹Ø´úÂë½øÐÐÄÚ¾ÛµÄÈ·¿ÉÒÔÌå»áµ½Î¬»¤µÄ·½±ã£¡
ÔÚJavaScriptÖÐÈçºÎ´´½¨¶ÔÏó£¿
JavaScriptÊÇ»ùÓÚ¶ÔÏóµÄ£¡ËüÒ²ÊÇÒÔObjectΪ¸ùÀ࣬ÆäËüÀà¼Ì³ÐÖ®¡£ÔÚ¸ùÀàÌṩÁ˼¸¸ö·½·¨¡£¹©¼Ì³ÐÀàʹÓã¡
ÒÔÏÂÊÇ´´½¨¶ÔÏóµÄÀý×Ó£º
funct ......

[·­Òë]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 ......

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

Regular Expression Optimization  ÕýÔò±í´ïʽÓÅ»¯
    Incautiously crafted regexes can be a major performance bottleneck (the upcoming section, "Runaway Backtracking" on page 91, contains several examples showing how severe this can be), but there is a lot you can do to improve re ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ