Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 typeofÓ¦ÓÃ

typeof ÊÇJavaScriptµÄÔËËã·û
    ——·µ»ØÒ»¸öÓÃÀ´±íʾ±í´ïʽµÄÊý¾ÝÀàÐ͵Ä×Ö·û´®
   typeof[(] expression [)]  //typeofÓï·¨ÖеÄÔ²À¨ºÅÊÇ¿ÉÑ¡Ïî
  typeof ÔËËã·û@import url(../html-vss/msdnie4a.css);
typeof
ÔËËã·û°ÑÀàÐÍÐÅÏ¢µ±×÷×Ö·û´®·µ»Ø¡£typeof
·µ»ØÖµÓÐÁ ......

JavaScript»ù´¡ÖªÊ¶3

Òþ²Ø³ÉÔ±±äÁ¿
ÔÚº¯ÊýÌåÄÚ¶¨ÒåµÄ±äÁ¿Îª¾Ö²¿±äÁ¿£¬À뿪º¯Êý¾Í¹ÒµôÁË
ÔÚº¯ÊýÌåÄÚʹÓÃthis.³ÉÔ±±äÁ¿Ãû£¬ÔòΪwindow¶ÔÏ󼶱äÁ¿£¬¼´È«¾Ö±äÁ¿
¹ÊÐèÒªÕâÑùÒþ²Ø³ÉÔ±±äÁ¿£¬ÏòÍâÖ»±©Â¶get¡¢setº¯Êý
function testClass(name){
var _firstname=name;
return {
getname : function() {
return _fir ......

javascriptʵÏÖ×Ô¶¯ÇóºÍ

function total(){
var i=0;
for(j=1;j<=20;j++)
{
var step="step"+j;
if(document.getElementById(step)){
if(document.getElementById(step).checked==true)
{
i=i+parseInt(document.getElementById(step).value);
}
}
}
document.getElementById("total").innerHTML = i;
}
function Resetvalue(){
......

[·­Òë]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(013)

Conditionals  Ìõ¼þ±í´ïʽ
    Similar in nature to loops, conditionals determine how execution flows through JavaScript. The traditional argument of whether to use if-else statements or a switch statement applies to JavaScript just as it does to other languages. Since different b ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ