Reputation: 16309
(Sorry, another this
question in javascript.)
I have the code below, and I'm wondering what 'this' represents in the call at the end-- the Window or the Bird?
var Bird = (function () {
Bird.name = 'Bird';
function Bird(name) {
this.name = name;
}
Bird.prototype.move = function (feet) {
return alert(this.name + (" flew" + feet + "ft."));
};
return Bird;
}).call(this);
Upvotes: 3
Views: 360
Reputation: 41832
Well, assuming there is no parent scope, it is window
EDIT: See example: http://jsfiddle.net/Umseu/1
Upvotes: 7
Reputation: 144
Call console.log(this)
at first line in the anonymous function. That return the scope, window
.
Upvotes: 1
Reputation: 13331
The window. .call(this)
is not written inside the bird. It simply calls an anonymous function that happen to return "Bird" "constructor".
Upvotes: 3
Reputation: 324650
Probably window
, because it's not in any particular context that would give this
any special meaning.
Upvotes: 5