ECMA262(v5)点滴(一)

本文解析了变量声明与初始化的过程,强调变量初始化发生在变量声明执行时而非创建时。通过实例说明了变量声明与初始化的两阶段过程,并指出这些操作依赖于执行上下文的建立。
 variable statment(变量语句)

A variable statement declares variables that are created as defined in 10.5. Variables are initialised to undefined when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.

 

这里很很重要的一句:

A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.
可见,如 var a=5;这种形式的语句是分两步进行的:

 

第一步,创建 variable a, 保证变量的存在

第二步,执行,对变量a赋值

 

如果像这样

var a=1 ;

var b=2;

var c=3;

则是:

第一步 ,创建变量a,b,c,此时他们的值都是undefined

第二部,对 a,b,c 分别赋值

 

注意:

只有当执行上下文(execution context)建立后才会进行上面的两步。

 

转载于:https://www.cnblogs.com/argb/archive/2011/07/06/2099298.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值