Calling function with window scope explanation (0, function(){})()

Viewed 2984

I am curious as to why this works:

var c = {
    d: function myFunc() {
        console.log(this === window);   
    }
};
var a = {
    b: function() {
        console.log(this === a);
        (0,c.d)();
        c.d();
    }
};
a.b();

Console output:

True
True
False

So it seems to be that (0, c.d)() is the same as c.d.call(window), but I cannot seem to find much about why or how this works. Can anyone explain?

From: Closure Compiler Issues

Fiddle: http://jsfiddle.net/wPWb4/2/

2 Answers
Related