Created
May 7, 2017 10:41
-
-
Save lenafaure/248cafd5a3655ecefe5a1319699b92b9 to your computer and use it in GitHub Desktop.
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 customer = { | |
firstName: "John", | |
lastName: "Doe", | |
greetCustomer: function(){ | |
console.log("Hello again " + this.firstName + " " + this.lastName + "!"); | |
}, | |
calculateAge: function(currentYear, birthDate){ | |
console.log(this.firstName + " is " + (currentYear - birthDate) + " years old."); | |
} | |
} | |
var customer3 = { | |
firstName: "Robert", | |
lastName: "Mills" | |
} | |
// bind returns a new ageOfCustomer3 with a 'this' that now refers to obj customer3 | |
var ageOfCustomer3 = customer.calculateAge.bind(customer3); | |
ageOfCustomer3(2016, 1978); // Prints Robert is 38 years old." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment