chapter2
stephansun (认真你就输了...)
- 章节名:chapter2
Summary Where you store and access data in JavaScript can have a measurable impact on the overall performance of your code. There are four places to access data from: literal values, variables, array items, and object members. These locations all have different performance considerations. • Literal values and local variables can be accessed very quickly, whereas array items and object members take longer. • Local variables are faster to access than out-of-scope variables because they exist in the first variable object of the scope chain. The further into the scope chain a variable is, the longer it takes to access. Global variables are always the slowest to access because they are always last in the scope chain. • Avoid the with statement because it augments the execution context scope chain. Also, be careful with the catch clause of a try-catch statement because it has the same effect. • Nested object members incur significant performance impact and should be minimized. • The deeper into the prototype chain that a property or method exists, the slower it is to access. • Generally speaking, you can improve the performance of JavaScript code by storing frequently used object members, array items, and out-of-scope variables in local variables. You can then access the local variables faster than the originals. By using these strategies, you can greatly improve the perceived performance of a web application that requires a large amount of JavaScript code.
stephansun对本书的所有笔记 · · · · · ·
-
第33页
One word of caution: it is not recommended to use this technique for object methods. Ma...
-
chapter2
说明 · · · · · ·
表示其中内容是对原文的摘抄