Name: Anonymous 2012-09-21 12:24
Javascript is surprisingly quirky for such a hyped language. Even Python has less quirks.
this, lack of operator overloading, semicolon insertion, retarded coercion rules, module support not part of the core, etc. also, "portable". yes, with native you have to port to other platforms; with javascript you have to port to different browsers, each with their own subset of javascript and their own vm/jit with its own runtime characteristics and god knows what else. keycodes? have fun!this but it never bothered me. Yes it's weird.
thisFoo.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();
}
Foo.prototype.method ?this always refers to the object the method was called on, i.e. that in that.test(). test() by itself uses the default (global) namespace.var self = this is so common that Vim's default JS syntax highlights self as a keyword.