var name = "Bob";
var book = {
name: "Harry Potter",
writeName: function() {
return function() {
document.writeln(this.book.name);
}
}
};
When I call this
book.writeName()();
I want it to print Harry Potter (not Bob) which it does above, however this:
var book2 = book;
book = null;
book2.writeName()();
Now looks for this.book (which is null) where it should be looking for this.book2
How can I reference the variable?
this.thiswhere inappropriate, like here inside the returned function wherethisrefers to the global object :-)