[翻译]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
相关文档:
页面一:
<html>
<head>
<title> 验证与提交一 </title>
<script>
function focusSelect(ID) //当验证不能通过时获得验证控件的焦点和内容
{
document.getElementById(I ......
1.在HTML中使用<script>元素引入JavaScript。
该元素有两个属性,language声明要使用的脚本语言,src属性是可选的,用于引用外部JavaScript文件。
NB
:现在大多使用type属性(type=“text/javascript”)替代language属性,以便更好地支持XHTML(可扩展HTML)。
2.一般认为 ......
// 调用页面的刷新方法
IHTMLWindow2* pWindow;
IHTMLDocument2* pDocument;
HRESULT hr = GetDHtmlDocument(&pDocument);
hr = pDocument->get_pa ......
J
SON (JavaScript Object Notation)一种简单的数据格式,比xml更轻巧。 JSON 是 JavaScript 原生格式,这意味着在 JavaScript 中处理 JSON 数据不需要任何特殊的 API 或工具包。
JSON的规则很简单: 对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“ ......
第二章:ECMAScript基础
1.当函数无明确返回值时,返回的也是值undefined
function testFunc(){}
alert(testFunc()==undefined);
2.typeof(null)=='object' //true,null可以解释为对象占位符
3.undefined 是声明了变量但未对其初始化时赋予该变量的值,null则用于表示尚未存在的对象。
alert(nu ......