In the following construct:
(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 window
object? Should everything inside IIFE be isolated from global scope? Are x
and y
functions also properties of window
global 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 window object -- I can just call show()
from the global scope! How come?