Last active
February 27, 2021 23:51
-
-
Save AnimeshPandey/afea3750e219b98bea75fd3e5bad97f3 to your computer and use it in GitHub Desktop.
Helpful example code to demonstrate the use of "this" in JavaScript for my article at https://anmshpndy.medium.com/how-well-do-you-know-this-ce4355bc9b
This file contains 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
// Example 4. Last level of an Object property chain | |
// matters for Implicit 'this' binding | |
function getBaseSpeed(){ | |
console.log("Base Speed Stat is : ", this.baseSpeed); | |
} | |
var pikachu = { | |
baseSpeed : 90, | |
getBaseSpeed : getBaseSpeed | |
}; | |
var raichu = { | |
baseSpeed : 110, | |
pikachu : pikachu | |
}; | |
raichu.pikachu.getBaseSpeed(); | |
// Output | |
// Base Speed Stat is : 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment