Skip to content

Instantly share code, notes, and snippets.

@snippe
Created November 15, 2014 10:02

Revisions

  1. snippe created this gist Nov 15, 2014.
    25 changes: 25 additions & 0 deletions this2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    var val = "window.val"

    var obj = {
    val: "obj.val",
    innerMethod: function () {
    var val = "obj.val.inner",
    func = function () {
    var self = this;
    return self.val;
    };
    return func;
    },
    outerMethod: function () {
    return this.val;
    }
    };

    //This actually gets executed inside window object
    console.log(obj.innerMethod()()); //returns window.val

    //Breakdown in to 2 lines explains this in detail
    var _inn = obj.innerMethod();
    console.log(_inn()); //returns window.val

    console.log(obj.outerMethod()); //returns obj.val