Reputation: 1521
Object({
a: "string",
b: function() { return a; }
}).b()
throws a is not defined
. Is it possible to access a
from inside b
?
Upvotes: 0
Views: 63
Reputation: 123428
Use this
to properly refer the scope
Object({
a: "string",
b: function() { return this.a; }
}).b(); // return "string"
See The this keyword on MDN for further reading.
Upvotes: 6