Reputation: 1225
How can I execute this anonymous function with the context of the function that's supplied from call?
function test(text) {
this.first = 'test';
console.log(this.first);
}
(function(val){
return function(val) {
console.log(this.first);
}
}()).call(test)
Upvotes: 1
Views: 56
Reputation: 1225
I did not incluse var self = this; before entering the return function:
(function(val){
var self = this; //add this line
return function(val) {
console.log(self.first);
}
}()).call(test)
Upvotes: 2
Reputation: 10755
I believe you get the value of what this
would be within the context of test
with test.prototype
.
Upvotes: 0