变量对象(VO)

Regarding the execution context of functions — there VO is inaccessible directly, and its role plays so-called an activation object (in abbreviated form — AO).

1 VO(functionContext) === AO;

An activation object is created on entering the context of a function and initialized by propertyarguments which value is the Arguments object:

1 AO = {
2   arguments: <ArgO>
3 };

Arguments object is a property of the activation object. It contains the following properties:

  • callee — the reference to the current function;
  • length — quantity of real passed arguments;
  • properties-indexes (integer, converted to string) which values are the values of function’s arguments (from left to right in the list of arguments). Quantity of these properties-indexes ==arguments.length. Values of properties-indexes of the arguments object and present (really passed) formal parameters are shared.

Example:

1 function foo(x, y, z) {
2   
3   // quantity of defined function arguments (x, y, z)
4   alert(foo.length); // 3
5  
6   // quantity of really passed arguments (only x, y)
7   alert(arguments.length); // 2
8  
9   // reference of a function to itself
10   alert(arguments.callee === foo); // true
11   
12   // parameters sharing
13  
14   alert(x === arguments[0]); // true
15   alert(x); // 10
16   
17   arguments[0] = 20;
18   alert(x); // 20
19   
20   x = 30;
21   alert(arguments[0]); // 30
22   
23   // however, for not passed argument z,
24   // related index-property of the arguments
25   // object is not shared
26   
27   z = 40;
28   alert(arguments[2]); // undefined
29   
30   arguments[2] = 50;
31   alert(z); // 40
32   
33 }
34   
35 foo(10, 20);

Concerning the last case, in older versions of Google Chrome there was a bug — there parameterz and arguments[2] were also shared.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值