易截截图软件、单文件、免安装、纯绿色、仅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和浏览器的推动作用远超过以往。其结果是出现了一些非常具体的模式,即有优秀的做法也有糟糕的做法。这些模式的出现,是因为网络上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基础知识2

玩PHP、Delphi、Java基本上都有对象,习惯这种思路后上手任何语言都想靠OO思路,这绝不是在赶时髦,而是把相关代码进行内聚的确可以体会到维护的方便!
在JavaScript中如何创建对象?
JavaScript是基于对象的!它也是以Object为根类,其它类继承之。在根类提供了几个方法。供继承类使用!
以下是创建对象的例子:
funct ......

Javascript闭包(Closure)

Closure中文翻译为闭包.字面上来理解就是"封闭的包".(这是一句废话)
闭包是什么?
书面解释为:
所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。
我认为闭包就是能够读/写函数内部的某些变量的子函数,并将这些变量保存 ......

[翻译]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 ......

[翻译]High Performance JavaScript(017)

A Note on Benchmarking  测试基准说明
    Because a regex's performance can be wildly different depending on the text it's applied to, there's no straightforward way to benchmark regexes against each other. For the best result, you need to benchmark your regexes on test strings o ......

[翻译]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号