Skip to content

Instantly share code, notes, and snippets.

@alexburner
Created December 20, 2011 03:48
Show Gist options
  • Save alexburner/1500142 to your computer and use it in GitHub Desktop.
Save alexburner/1500142 to your computer and use it in GitHub Desktop.
"this" and nested object methods
// exploring javascript's nefarious this
this.level = 0;
var test = {
level: 1,
method: function () {
console.log( this.level );
},
test: {
level: 2,
method: function () {
console.log( this.level );
},
test: {
level: 3,
method: function () {
console.log( this.level );
},
}
}
};
test.method(); // level 1
test.test.method(); // level 2
test.test.test.method(); // level 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment