Module3: What is bind method?

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

18
app.js
View File

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