I\'ve noticed that calls like setTimeout() work either as :
self.keyword()
or just on their own e.g. keyword().
It works with setTimeout because of two conditions in the browser:
window object. That means that window has a property setTimeout (window.setTimeout).window object has a property called self that points to itself.As you can access the properties of window without explicitly writing window (that is what makes the global variables global), both calls work: setTimeout() will look up the property setTimeout() on the window object. self.setTimeout() will look up the property self on the window object, which is the window object itself.
So if you call self.setTimeout() it is the same as window.self.setTimeout() which is the same as window.setTimeout() which again is the same as setTimeout().
Note: This only works if there is no variable self defined in the current scope that shadows the global self.
This works with any symbol (meaning variable or function) defined in the global scope. You can test it yourself:
alert(window.self);
and
alert(self);
should both alert
[object Window]