<<High Performance JavaScript>>读书笔记-2.Data Access
2012-08-09 11:05
543 查看
Scope Chains and Identifier Resolution
Scope Chain Augmentation
with表达式会临时改变execution context中的Scope chain,一个新的包含指定对像所有属性的可变对象被插入到execution
context的scopechain的最前端。这样local variable的访问就会变慢,所以不要使用with。
Dynamic Scopes
Both the with statement and the catch clause of a try-catch statement, as well as a function containing
eval(), are all considered to be dynamic scopes.
Closures, Scope, and Memory
通常Activationobject会同execution
context一起销毁,但是使用了closure后,Activation object仍然被closure引用,所以还不能销毁。
因此使用闭包的函数比未使用闭包的函数需要更多的内存
访问id和saveDocument会有性能下降
Object Members
function add(num1, num2){ var sum = num1 + num2; return sum; }
Scope Chain Augmentation
with表达式会临时改变execution context中的Scope chain,一个新的包含指定对像所有属性的可变对象被插入到execution
context的scopechain的最前端。这样local variable的访问就会变慢,所以不要使用with。
try { methodThatMightCauseAnError(); } catch (ex){ alert(ex.message); //scope chain is augmented here }
Dynamic Scopes
Both the with statement and the catch clause of a try-catch statement, as well as a function containing
eval(), are all considered to be dynamic scopes.
Closures, Scope, and Memory
function assignEvents(){ var id = "xdi9592"; document.getElementById("save-btn").onclick = function(event){ saveDocument(id); }; }
通常Activationobject会同execution
context一起销毁,但是使用了closure后,Activation object仍然被closure引用,所以还不能销毁。
因此使用闭包的函数比未使用闭包的函数需要更多的内存
访问id和saveDocument会有性能下降
Object Members
function Book(title, publisher){ this.title = title; this.publisher = publisher; } Book.prototype.sayTitle = function(){ alert(this.title); };
相关文章推荐
- <<High Performance JavaScript>>读书笔记-3.DOM Scripting
- <<High Performance JavaScript>>读书笔记-5.Strings and Regular Expressions
- <<High Performance JavaScript>>读书笔记-6.Responsive Interfaces
- <<High Performance JavaScript>>读书笔记-7.Ajax
- <<High Performance JavaScript>>读书笔记-8.Programming Practices
- <<High Performance JavaScript>>读书笔记-10.Tools
- <<High Performance JavaScript>>读书笔记-1.Loading and Execution
- <读书笔记>Javascript系列之6种继承(面向对象)
- <读书笔记>JavaScript系列之7种创建对象(面向对象)
- Notes On <Enterprise AJAX – Strategies for Building High Performance Web Applications> - 1
- <分布式程序设计> 读书笔记一
- <Python for Kids>读书笔记
- JavaScript中的<noscript>元素
- <<C++的设计与演化>>读书笔记(二)
- <javascript>每日一记
- <a href="#">与<a href="javascript:void(0)">
- <从PAXOS到ZOOKEEPER分布式一致性原理与实践>读书笔记-ZAB协议
- <<C++Primer PLus 第五版>>读书笔记2
- <图形图像,动画,多媒体> 读书笔记 --- 录制与编辑视频
- <图形图像,动画,多媒体> 读书笔记 --- 音效