Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ЧÂʾ­Ñé̸(Ò»)

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

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

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

JavaScript»ù´¡ÖªÊ¶1

JavascriptÊý¾ÝÀàÐÍ
ÓÉÓÚjavascriptÊÇÈõÀàÐÍÓïÑÔ£¬¼´¶¨Òå±äÁ¿Ê±²»±ØÉùÃ÷ÆäÀàÐÍ
¡£µ«Õâ²¢²»Òâζ×űäÁ¿Ã»ÓÐÀàÐÍ¡£ÒòΪ¸³ÖµÊ±»á×Ô¶¯Æ¥ÅäÊý¾ÝÀàÐÍ£¡
ĿǰÓõ½µÄ»ù±¾Êý¾ÝÀàÐÍ
number
boolean
string
var i
i="test";//Õâʱi¾Í³ÉÁËstringÀàÐÍ
var i
i=4;//Õâʱi¾Í³ÉÁËnumberÀàÐÍ
³£ÓöÔÏóÀàÐÍ<object> ......

javascript¶¯Ì¬×°ÈëXMLÊý¾Ý


ʹÓÃjavascript´´½¨Microsoft XML DOM,¾Í¿ÉÒÔÍê³ÉÕâÒ»¹¤×÷.
// ×°ÈëÊý¾Ý.
var source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false
source.load("history.xml");
// ×°ÈëÑùʽ±í.
var stylesheet = new ActiveXObject("Microsoft.XMLDOM");
stylesheet.async = false
stylesheet.load( ......

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