[翻译]High Performance JavaScript(006)
Identifier Resolution Performance 标识符识别性能
Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for both reads and writes. Consequently, local variables are always the fastest to access inside of a function, whereas global variables will generally be the slowest (optimizing JavaScript engines are capable of tuning this in certain situations). Keep in mind that global variables always exist in the last variable object of the execution context's scope chain, so they are always the furthest away to resolve. Figures 2-4 and 2-5 show the speed of identifier resolution based on their depth in the scope chain. A depth of 1 indicates a local variable.
标识符识别不是免费的,事实上没有哪种电脑操作可以不产生性能开销。在运行期上下文的作用域链中,一个标识符所处的位置越深,它的读写速度就越慢。所以,函数中局部变量的访问速度总是最快的,而全局变量通常是最慢的(优化的JavaScript引擎在某些情况下可以改变这种状况)。请记住,全局变量总是处于运行期上下文作用域链的最后一个位置,所以总是最远才能触及的。图2-4和2-5显示了作用域链上不同深度标识符的识别速度,深度为1表示一个局部变量。
Figure 2-4. Identifier resolution for write operations
图2-4 写操作的标识符识别速度
Figure 2-5. Identifier resolution for read operations
图2-5 读操作的标识符识别速度
The general trend across all browsers is that the deeper into the scope chain an identifier exists, the slower it will be read from or written to. Browsers with optimizing JavaScript engines, such as Chrome and Safari 4, don't have this sort of performance penalty for accessing out-of-scope identifiers, whereas Internet Explorer, Safari 3.2, and others show a more drastic effect. It's worth noting that earlier browsers, such as Internet Explorer 6 and Firefox 2, had incredibly steep slopes and would no
相关文档:
学习Javascript,最难的地方是什么?
我觉得,Object(对象)最难。因为Javascript的Object模型很独特,和其他语言都不一样,初学者不容易掌握。
下面就是我的学习笔记,希望对大家学习这个部分有所帮助。我主要参考了Object-Oriented JavaScript和Professional JavaScript for Web Developers (2nd Edition)这两本书。 ......
最近编写Javascript代码。起初没管那么多。一阵狂写。代码写得差不多了。结果上百K文件几十个。当然 没办法需要压缩了。为了速度。
找压缩工具。弄了下。结果错误一大堆。最后才发现是自己写的代码不规范导致的。检查了半天修正了几十个地方。终于能压缩了。
下面总结下需要注意的地方
1、对象结尾 function结尾 最 ......
<script>setTimeout("redirect('<?=$url_forward?>');", <?=$ms?>);</script>
设置分页:$page $pagesize $offset = ($page-1)*$pagesize;
$limit = "limit $offset,$pagesize" ......
**
* 我在网上看到过很多BASE64的JavaScript算法,都觉得不满意,于是自己写了一个,在这里分享一下。
* 我的代码在质量的效率都较高,没有一些冗余的操作。总体来讲我觉得非常不错。
* 如果大家有什么不懂的地方可以问我。
*/
var BASE64={
/**
* 此变量为编码的 ......
1.浮点运算
这可能是挫败一些对javascript不熟悉并准备执行一些数学运算的人的主要原
因.
<script>
alert(0.02 / 0.1); //0.19999999999999998
alert(1.14 * 100); //113.99999999999999 ;)
......