var foo = { x: 1, y: (function () { return ++this.x; })() }; console.log(foo.y); // undefined rather than 2 Let's say that I want to be able to reference foo.y without using foo.y(). Is that possible?
The above obviously doesn't work, and I'm assuming it is because closure references a different this.
thisat all, it is an IIFE (Immediately Invoked Function Expression), and doesn't get any otherthiscontext other than the globalthis, which is probablywindow, if you're working within the browser, as it seems you are.