Skip to content

Instantly share code, notes, and snippets.

@flipjs
Created August 6, 2014 22:42
Show Gist options
  • Save flipjs/e349030bbc7ae0036659 to your computer and use it in GitHub Desktop.
Save flipjs/e349030bbc7ae0036659 to your computer and use it in GitHub Desktop.
The Contextual This
var obj = {
name: 'flip',
printMe: function() {
// solution: pass this as closure
var self = this
console.log('1. ' + this.name)
var x = (function() {
// console.log('2. ' + this.name)
console.log('2. ' + self.name)
var y = (function() {
// console.log('3. ' + this.name)
console.log('3. ' + self.name)
})()
})()
}
}
obj.printMe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment