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

[·­Òë]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 browsers have implemented different flow control optimizations, it is not always clear which technique to use.
    ÓëÑ­»·ÏàËÆ£¬Ìõ¼þ±í´ïʽ¾ö¶¨JavaScriptÔËÐÐÁ÷µÄ×ßÏò¡£ÆäËûÓïÑÔʹÓÃif-else»òÕßswitch±í´ïʽµÄ´«Í³¹ÛµãÒ²ÊÊÓÃÓÚJavaScript¡£ÓÉÓÚ²»Í¬µÄä¯ÀÀÆ÷Õë¶ÔÁ÷³Ì¿ØÖƽøÐÐÁ˲»Í¬µÄÓÅ»¯£¬Ê¹ÓÃÄÄÖÖ¼¼Êõ²¢²»×ÜÊǺÜÇå³þ¡£
if-else Versus switch  if-elseÓëswitch±È½Ï
    The prevailing theory on using if-else versus switch is based on the number of conditions being tested: the larger the number of conditions, the more inclined you are to use a switch instead of if-else. This typically comes down to which code is easier to read. The argument is that if-else is easier to read when there are fewer conditions and switch is easier to read when the number of conditions is large. Consider the following:
    ʹÓÃif-else»òÕßswitchµÄÁ÷ÐÐÀíÂÛÊÇ»ùÓÚ²âÊÔÌõ¼þµÄÊýÁ¿£ºÌõ¼þÊýÁ¿½Ï´ó£¬ÇãÏòÓÚʹÓÃswitch¶ø²»ÊÇif-else¡£Õâͨ³£¹é½áµ½´úÂëµÄÒ×¶ÁÐÔ¡£ÕâÖÖ¹ÛµãÈÏΪ£¬Èç¹ûÌõ¼þ½ÏÉÙʱ£¬if-elseÈÝÒ×ÔĶÁ£¬¶øÌõ¼þ½Ï¶àʱswitch¸üÈÝÒ×ÔĶÁ¡£¿¼ÂÇÏÂÃæ¼¸µã£º
if (found){
  //do something
} else {
  //do something else
}
switch(found){
  case true:
    //do something
    break;
  default:
    //do something else
}
    Though both pieces of code perform the same task, many would argue that the if-else statement is much easier to read than the switch. Increasing the number of conditions, however, usually reverses that opinion:
    ËäÈ»Á½¸ö´úÂë¿éʵÏÖͬÑùÈÎÎñ£¬ºÜ¶àÈË»áÈÏΪif-else±í´ïʽ±Èwitch±í´ïʽ¸üÈÝÒ×ÔĶÁ¡£Èç¹ûÔö¼ÓÌõ¼þÌåµÄÊýÁ¿£¬Í¨³£»áŤתÕâÖֹ۵㣺
if (color == "red"){
  //do


Ïà¹ØÎĵµ£º

javascript¿çä¯ÀÀÆ÷´´½¨XML¶ÔÏó


var
 
xmlDoc
 
=
 
null
;
function
 
parseXML
(
xmlUrl
)
{
¡¡¡¡try
 
{
¡¡¡¡¡¡¡¡//IE
¡¡¡¡¡¡¡¡xmlDoc
 
=
 
new
 
ActiveXObject
(
"Microsoft.XMLDOM"
);
¡¡¡¡¡¡¡¡xmlDoc
.
async
 
=
 
false
;
¡¡¡¡¡¡¡¡xmlDoc ......

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

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

javascript typeofÓ¦ÓÃ

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

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(011)

Repaints and Reflows  ÖØ»æºÍÖØÅŰæ
    Once the browser has downloaded all the components of a page—HTML markup, JavaScript, CSS, images—it parses through the files and creates two internal data structures:
    µ±ä¯ÀÀÆ÷ÏÂÔØÍêËùÓÐÒ³ÃæHTML±ê¼Ç£¬JavaScri ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ