Skip to content

Commit 95bfc1f

Browse files
committed
objects
1 parent 093b607 commit 95bfc1f

14 files changed

+88
-1
lines changed
File renamed without changes.

Objects/10.apply.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// call & apply
2+
3+
const john = {
4+
name: 'john',
5+
age: 25,
6+
};
7+
8+
const susy = {
9+
name: 'susy',
10+
age: 27,
11+
};
12+
13+
function greeting(city, country) {
14+
console.log(this);
15+
console.log(
16+
`Hello ${this.name} your age is ${this.age} and your live in ${city}, ${country}`
17+
);
18+
}
19+
20+
// here different call & apply
21+
// call for argument is ***list argument***
22+
greeting.call(john, 'bandung', 'West in java');
23+
greeting.call(susy, 'bandung', 'West in java');
24+
greeting.call({ name: 'natsui', age: 42 }, 'tokyo', 'japan');
25+
// *** output
26+
// Hello john your age is 25 and your live in bandung, West in java
27+
// Hello susy your age is 27 and your live in bandung, West in java
28+
29+
// apply for argument is ***ARRAY***
30+
greeting.apply({ name: 'peter', age: 30 }, ['amsterdam', 'Netherlands']);
31+
greeting.apply(susy, ['riyadh', 'saudi arabian']);

0 commit comments

Comments
 (0)