Module3: What is bind method?
This commit is contained in:
parent
6a0a672e35
commit
2ad7483250
16
app.js
16
app.js
@ -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());
|
Loading…
x
Reference in New Issue
Block a user