Created
July 25, 2020 01:57
-
-
Save a-laughlin/06ef449848077d6c5cb30452016187fd to your computer and use it in GitHub Desktop.
prototype chain
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
var mufasa = { | |
name: "Mufasa", | |
sing() { | |
var inner = function() { | |
console.log("inner:this", this); | |
}; | |
var innerStrict = function() { | |
'use strict'; | |
console.log("innerStrict:this", this); | |
}; | |
var innerArrow = ()=>console.log("innerArrow:this", this) | |
var innerArrowStrict = ()=>{ | |
'use strict'; // doesn't matter in an arrow function | |
console.log("innerArrowStrict:this", this); | |
} | |
console.log("sing", this); | |
inner(); | |
innerStrict(); | |
innerArrow(); | |
innerArrowStrict(); | |
} | |
}; | |
var simba = {name:'Simba'}; | |
console.log('\nmufasa.sing(); ... calling sing in the context of mufasa') | |
mufasa.sing(); | |
console.log('\nmufasa.sing.call(simba); ... calling sing in the context of simba') | |
mufasa.sing.call(simba); | |
console.log('\nsimba.sing=mufasa.sing;simba.sing(); ... assigning sing to a different context') | |
simba.sing=mufasa.sing;simba.sing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment