Created
August 6, 2014 22:42
-
-
Save flipjs/e349030bbc7ae0036659 to your computer and use it in GitHub Desktop.
The Contextual This
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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