[翻译]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 determined simply by static analysis (looking at the code structure). For example:
无论是with表达式还是try-catch表达式的catch子句,以及包含eval_r()的函数,都被认为是动态作用域。一个动态作用域只因代码运行而存在,因此无法通过静态分析(察看代码结构)来确定(是否存在动态作用域)。例如:
function execute(code) {
eval_r(code);
function subroutine(){
return window;
}
var w = subroutine();
//what value is w?
};
The execute() function represents a dynamic scope due to the use of eval_r(). The value of w can change based on the value of code. In most cases, w will be equal to the global window object, but consider the following:
execute()函数看上去像一个动态作用域,因为它使用了eval_r()。w变量的值与code有关。大多数情况下,w将等价于全局的window对象,但是请考虑如下情况:
execute("var window = {};")
In this case, eval_r() creates a local window variable in execute(), so w ends up equal to the local window instead of the global. There is no way to know if this is the case until the code is executed, which means the value of the window identifier cannot be predetermined.
这种情况下,eval_r()在execute()函数中创建了一个局部window变量。所以w将等价于这个局部window变量而不是全局的那个。所以说,不运行这段代码是没有办法了解具体情况的,标识符window的确切含义不能预先确定。
Optimizing JavaScript engines such as Safari's Nitro try to speed up identifier resolution by analyzing the code to determine which variables should be accessible at any given time. These engines try to avoid the traditional scope chain lookup by inde
相关文档:
页面提交数据一般有两种方法:get,post。post就是所谓的form提交,使用视图;get是通过url提交。
Get方法一般用后台代码(如asp,asp.net)获得参数,代码很简单:Request.QueryString["id"];即可获取。
有些时候需要直接在前台获取url参数,要用到javascript,js没有直接获取url参数的方法,那么,我们如何通过js ......
Primitive types
1. undefined, null, boolean, number, string; undefined is derived from null.
e.g. var tmp; typeof tmp == undefined.
e.g. void(javascript:aler(‘x’)) == undefined.
e.g. undefined==null
2. NaN!=NaN isNaN(“123”)==false isNaN(“blue”)==true ......
学习Javascript,最难的地方是什么?
我觉得,Object(对象)最难。因为Javascript的Object模型很独特,和其他语言都不一样,初学者不容易掌握。
下面就是我的学习笔记,希望对大家学习这个部分有所帮助。我主要参考了Object-Oriented JavaScript和Professional JavaScript for Web Developers (2nd Edition)这两本书。 ......
第二章:ECMAScript基础
1.当函数无明确返回值时,返回的也是值undefined
function testFunc(){}
alert(testFunc()==undefined);
2.typeof(null)=='object' //true,null可以解释为对象占位符
3.undefined 是声明了变量但未对其初始化时赋予该变量的值,null则用于表示尚未存在的对象。
alert(nu ......
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 ......