不能指出你的规格,但我强烈推荐阅读Douglas Crockford's "Javascript: The good parts"。本书将帮助您理解JavaScript的大部分奇怪但强大的功能。
作为你的问题:
- foo.bar(),在
bar
功能 this
关键字被绑定到对象foo
- (foo.bar)()是与上述相同,
在JavaScript中,您可以多次指定从右到左的变量
z = 3; x =(y = z); console.log(x); // 3
函数作为其他任何变量。因此,您将函数foo.bar
分配给foo.bar
,但括号会使分配的函数返回并执行。
(foo.bar = foo.bar)();
//is the same as
var f = (foo.bar = foo.bar);
f();
//and this also the same as:
var f= foo.bar;
f();
该函数返回从括号没有绑定到任何东西,所以this
将引用全局对象,在浏览器的情况下 - 在window
对象。
4。该条款(foo.bar,foo.bar)()仅仅是相似:
a = (3, 4); //last value is returned, first just parsed.
//a contains 4
var f = (foo.bar, foo.bar);
//f contains body of foo.bar function,
f() // is executed in the context of `global` object, eg. `window`.
请阅读的JavaScript功能有关binding
。
在IE看来输出是20,20,undefined,undefined .. – RameshVel 2010-02-19 09:57:05