Skip to content

Instantly share code, notes, and snippets.

@micmath
Created May 23, 2011 13:28
Show Gist options
  • Save micmath/986691 to your computer and use it in GitHub Desktop.
Save micmath/986691 to your computer and use it in GitHub Desktop.
What "this" references, inside inner functions.
var x = 1;
function Foo() {
this.x = 2;
function bar() {
console.log(this.x); //=> 1
}
bar();
var zop = function() {
console.log(this.x); //=> 1
}
zop();
var that = this;
function fez() {
console.log(that.x); //=> 2
}
fez();
}
new Foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment