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 11. Implicit versus new | |
function catchPokémon(name) { | |
this.name = name; | |
} | |
var firstAttempt = { | |
catchPokémon : catchPokémon | |
}; | |
var secondAttempt = {}; |
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 12. Explicit versus new through hard-binding | |
function catchPokémon(name) { | |
this.name = name; | |
} | |
var firstAttempt = {}; | |
var attemptBinder = catchPokémon.bind(firstAttempt); | |
attemptBinder("Onix"); | |
console.log(firstAttempt.name); | |
// Output : "Onix" |
OlderNewer