javascript "this" points to Window object again
Posted
by terrani
on Stack Overflow
See other posts from Stack Overflow
or by terrani
Published on 2010-05-02T02:52:00Z
Indexed on
2010/05/02
2:57 UTC
Read the original article
Hit count: 294
Hello,
I asked a question on http://stackoverflow.com/questions/2719643/javascript-this-points-to-window-object regarding "this" points to Window object.
here is source code
var archive = function(){}
archive.prototype.action = {
test: function(callback){
callback();
},
test2: function(){
console.log(this);
}
}
var oArchive = new archive();
oArchive.action.test(oArchive.action.test2);
Tim Down wrote "but that function is then called using callback(), which means it is not called as a method and hence this is the global object".
What are differences between calling a function by its actual name and callback() as shown on the source code?
How does console.log(this) in test2 points to Window when it is inside archive.action???
© Stack Overflow or respective owner