Created
October 24, 2018 05:21
-
-
Save dsaw/2d2a35a479d4dff8ce124fdf2b32ddbf to your computer and use it in GitHub Desktop.
Little script to recap on this binding rules.
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
function displaySome(blah) | |
{ | |
console.log(this.blah); | |
console.log(this); | |
} | |
var blah = "suit yourself!"; | |
var bleh = "don't leave, you lizard!"; | |
// default binding | |
displaySome(bleh); | |
// implicit binding | |
var obj = | |
{ | |
blah: "party in the house, tonight!", | |
func: displaySome | |
} | |
obj.func(bleh); | |
// explicit binding | |
displaySome.call(obj,bleh); | |
// new binding | |
var fobj = new displaySome(bleh); | |
fobj.blah = "jerk"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment