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

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

µÚ°ËÕ  Programming Practices  ±à³Ìʵ¼ù
    Every programming language has pain points and inefficient patterns that develop over time. The appearance of these traits occurs as people migrate to the language and start pushing its boundaries. Since 2005, when the term "Ajax" emerged, web developers have pushed JavaScript and the browser further than it was ever pushed before. As a result, some very specific patterns emerged, both as best practices and as suboptimal ones. These patterns arise because of the very nature of JavaScript on the Web.
    ÿÖÖ±à³ÌÓïÑÔ¶¼ÓÐÍ´µã£¬¶øÇÒµÍÐ§Ä£Ê½Ëæ×Åʱ¼äµÄÍÆÒÆ²»¶Ï·¢Õ¹¡£ÆäÔ­ÒòÔÚÓÚ£¬Ô½À´Ô½¶àµÄÈËÃÇ¿ªÊ¼Ê¹ÓÃÕâÖÖÓïÑÔ£¬²»¶ÏÀ©ÖÖËüµÄ±ß½ç¡£×Ô2005ÄêÒÔÀ´£¬µ±ÊõÓï“Ajax”³öÏÖʱ£¬ÍøÒ³¿ª·¢Õß¶ÔJavaScriptºÍä¯ÀÀÆ÷µÄÍÆ¶¯×÷ÓÃÔ¶³¬¹ýÒÔÍù¡£Æä½á¹ûÊdzöÏÖÁËһЩ·Ç³£¾ßÌåµÄģʽ£¬¼´ÓÐÓÅÐãµÄ×ö·¨Ò²ÓÐÔã¸âµÄ×ö·¨¡£ÕâЩģʽµÄ³öÏÖ£¬ÊÇÒòÎªÍøÂçÉÏJavaScriptµÄÐÔÖʾö¶¨µÄ¡£
Avoid Double Evaluation  ±ÜÃâ¶þ´ÎÆÀ¹À
    JavaScript, like many scripting languages, allows you to take a string containing code and execute it from within running code. There are four standard ways to accomplish this: eval(), the Function() constructor, setTimeout(), and setInterval(). Each of these functions allows you to pass in a string of JavaScript code and have it executed. Some examples:
    JavaScriptÓëÐí¶à½Å±¾ÓïÑÔÒ»Ñù£¬ÔÊÐíÄãÔÚ³ÌÐòÖлñȡһ¸ö°üº¬´úÂëµÄ×Ö·û´®È»ºóÔËÐÐËü¡£ÓÐËÄÖÖ±ê×¼·½·¨¿ÉÒÔʵÏÖ£ºeval()£¬Function()¹¹ÔìÆ÷£¬setTimeout()ºÍsetInterval()¡£Ã¿¸öº¯ÊýÔÊÐíÄã´«ÈëÒ»´®JavaScript´úÂ룬ȻºóÔËÐÐËü¡£ÀýÈ磺
var num1 = 5,
num2 = 6,
//eval() evaluating a string of code
result = eval("num1 + num2"),
//Function() evaluating strings of code
sum = new Function("arg1", "arg2", "return arg1 + arg2");
//setTimeout() evaluating a string of code
setTimeout("sum = num1 + num2", 100);
//setInterval() evaluating a string of code
setInterval("sum = num1 + num2", 100);
    Whenever you're evaluating Jav


Ïà¹ØÎĵµ£º

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»ù´¡ÖªÊ¶3

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

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

Recursion Patterns  µÝ¹éģʽ
    When you run into a call stack size limit, your first step should be to identify any instances of recursion in the code. To that end, there are two recursive patterns to be aware of. The first is the straightforward recursive pattern represented ......

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