In the following construction:
(function(){ var x = function(){ alert('hi!'); } var y = function(){ alert("hi again!"); } this.show = function(){ alert("This is show function!"); } })();
Why does this refer to the window object? Should everything inside IIFE be isolated from the global realm? Are x and y also functions of the properties of the global window object?
Also, even if I use put var h = ... at the beginning:
var h = (function(){ var x = function(){ alert('hi!'); } var y = function(){ alert("hi again!"); } this.show = function(){ alert("This is show function!"); } })();
this still refers to the window object - I can just call show() from the global scope! Why?
DrStrangeLove
source share