Created
May 17, 2016 00:45
-
-
Save andrewjmead/9a4e37ffc95d3f425149761d1633221f to your computer and use it in GitHub Desktop.
Example of custom this keyword
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 = { | |
age: 99, | |
someFunc: function () { | |
console.log('age', this.age); | |
} | |
} | |
// Uses the default this definition which would be the obj object | |
obj.someFunc(); | |
// Has the this keyword set to whatever you want! | |
obj.someFunc.apply({age: 25}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment