【发布时间】:2013-02-13 05:36:18
【问题描述】:
这是一个例子:
function one() {
var a = 1;
two();
function two() {
var b = 2;
three();
function three() {
var c = 3;
alert(a + b + c); // 6
}
}
}
one(); //calling the function
现在当我们调用函数 one() 时,结果是6。
所以这都是关于作用域链的,所有变量都解决了,现在我有一个问题。
当所有变量都通过作用域链解析时,为什么我们需要这个“this”关键字?
所以如果我们有以下函数:
function a() {
var a = 'function a';
function b() {
var b = 'function b';
alert (a); //will be function a, without keyword this
alert (this.a); // what will be the effect of this line
}
}
“this”关键字总是让我感到困惑!
请哪位大神简单详细的解释一下。
【问题讨论】:
-
这不是你想的那样。
标签: javascript scope this