Name: Anonymous 2012-09-21 12:24
Javascript is surprisingly quirky for such a hyped language. Even Python has less quirks.
Foo.method = function() {
function test() {
// this is set to the global object
}
test();
}this inside of test refers to Foo; while in fact, it does not.Foo from within test, it is necessary to create a local variable inside of method which refers to Foo.Foo.method = function() {
var that = this;
function test() {
// Use that instead of this here
}
test();
}