var a = 1;
var b = {
a : 2,
c : function () {
console.log(this.a);
}
};
b.c(); // logs 2
(b.c)(); // logs 2
(0, b.c)(); // logs 1
Run Code Online (Sandbox Code Playgroud)
第一个是可以理解的,因为"this"指的是Object"b".但为什么第二个会记录相同的结果呢?我认为"this"应该指向全局执行上下文.第三个,似乎逗号运算符影响执行上下文.
有类似的东西
f.call(...)
f.apply(...)
Run Code Online (Sandbox Code Playgroud)
但那就是这个
(1, alert)('Zomg what is this????!!!11')
Run Code Online (Sandbox Code Playgroud)
在这种情况下,"1"似乎没有多大意义,以下工作正常:
(null, alert)('Zomg what is this????!!!11')
(1, null, alert)('Zomg what is this????!!!11')
(undefined, alert)('Zomg what is this????!!!11')
Run Code Online (Sandbox Code Playgroud)
你能指出一下描述语法的ECMAScript的特定部分吗?
以下是这个问题
function q() {
console.log((0, eval)('this'));
}
Run Code Online (Sandbox Code Playgroud)
返回[对象窗口]。
我没有得到的是这个的(0,eval)部分。
JS在做什么呢?
它表示从链接中间接调用eval()。间接是什么意思?