What is the apply Method?

Module3_Changing_Functions_Context_and_Built-in_Functions
jason.zhu 2021-05-12 13:48:15 +10:00
parent 0c245858e6
commit 6a0a672e35
1 changed files with 7 additions and 7 deletions

14
app.js
View File

@ -1,7 +1,7 @@
let person1 = {name: 'John', age: 22};
let person2 = {name: 'Mary', age: 26};
let sayHi = function() {
console.log('Hi, ' + this.name);
};
sayHi.call(person1);
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');