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