Module3: What is bind method?

This commit is contained in:
jason.zhu 2021-05-12 17:02:11 +10:00
parent 6a0a672e35
commit 2ad7483250

16
app.js
View File

@ -1,7 +1,11 @@
function introduction(name, profession) { let person1 = {
console.log('My name is ' + name + ' and I am a ' + profession + '.'); name: 'Mary',
console.log(this); getName: function(){
return this.name;
} }
introduction('John', 'student'); };
introduction.apply(undefined, ['Mary', 'Lawyer']); let person2 = {
introduction.call(undefined, 'James', 'artiest'); name: 'John'
};
let getNameCopy = person1.getName.bind(person2); // won't change context of function
console.log(getNameCopy());