易截截图软件、单文件、免安装、纯绿色、仅160KB

[翻译]High Performance JavaScript(008)

Nested Members  嵌套成员
    Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is encountered. Figure 2-12 shows the relationship between object member depth and time to access.
    由于对象成员可能包含其它成员,例如不太常见的写法window.location.href这种模式。每遇到一个点号,JavaScript引擎就要在对象成员上执行一次解析过程。图2-12显示出对象成员深度与访问时间的关系。
Figure 2-12. Access time related to property depth
图2-12  访问时间与属性深度的关系
    It should come as no surprise, then, that the deeper the nested member, the slower the data is accessed. Evaluating location.href is always faster than window.location.href, which is faster than window.location.href.toString(). If these properties aren't on the object instances, then member resolution will take longer as the prototype chain is searched at each point.
    结果并不奇怪,成员嵌套越深,访问速度越慢。location.href总是快于window.location.href,而后者也要比window.location.href.toString()更快。如果这些属性不是对象的实例属性,那么成员解析还要在每个点上搜索原形链,这将需要更长时间。
Caching Object Member Values  缓存对象成员的值
    With all of the performance issues related to object members, it's easy to believe that they should be avoided whenever possible. To be more accurate, you should be careful to use object member only when necessary. For instance, there's no reason to read the value of an object member more than once in a single function:
    由于所有这些性能问题与对象成员有关,所以如果可能的话请避免使用它们。更确切地说,你应当小心地,只在必要情况下使用对象成员。例如,没有理由在一个函数中多次读取同一个对象成员的值:
function hasEitherClass(element, className1, className2){
  return element.c


相关文档:

JavaScript 规范编写

最近编写Javascript代码。起初没管那么多。一阵狂写。代码写得差不多了。结果上百K文件几十个。当然 没办法需要压缩了。为了速度。
找压缩工具。弄了下。结果错误一大堆。最后才发现是自己写的代码不规范导致的。检查了半天修正了几十个地方。终于能压缩了。
下面总结下需要注意的地方
1、对象结尾 function结尾 最 ......

JavaScript:history.go() 的妙用(转)

  在Web开发中,会遇到从一页(父页)导向另一页(子页),并且要求“返回”父页的情况,在这里如果用ASP.NET提供的 Response.Redirect()方法,往往不会达到理想的效果,例如:返回后,重新加载了页面,无法保存导向子页前的状态,等等,在这里我就介绍 一下如何使用JavaScript中history.go()函数来实现返回 ......

JavaScript学习笔记(六)

1.DOM是针对XML的基于树的API。使用DOM,只需解析代码一次来创建一个树的模型。在这个初始解析过程之后,XML已经完全通过DOM模型表现出来,同时也不再需要原始的代码。
   NB
:DOM是语言无关的API,它并不与Java、JavaScript或其他语言绑定。 ......

Javascript陷阱。。。。。。。

1.浮点运算
这可能是挫败一些对javascript不熟悉并准备执行一些数学运算的人的主要原
因.
<script>  
alert(0.02 / 0.1);  //0.19999999999999998 
  
alert(1.14 * 100);  //113.99999999999999    ;)
  
......

[翻译]High Performance JavaScript(007)

Dynamic Scopes  动态作用域
    Both the with statement and the catch clause of a try-catch statement, as well as a function containing eval_r(), are all considered to be dynamic scopes. A dynamic scope is one that exists only through execution of code and therefore cannot be det ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号