Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java's Crypt

Name: Anonymous 2012-09-21 12:24

Javascript is surprisingly quirky for such a hyped language.  Even Python has less quirks.

Name: Anonymous 2012-09-24 5:44

While most of these cases make sense, the first one is to be considered another mis-design of the language because it never has any practical use.

Foo.method = function() {
    function test() {
        // this is set to the global object
    }
    test();
}


A common misconception is that this inside of test refers to Foo; while in fact, it does not.

In order to gain access to 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();
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List