-
Notifications
You must be signed in to change notification settings - Fork 6
/
call.js
44 lines (34 loc) · 803 Bytes
/
call.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// function sum(a,b,c) {
// return a+b+c;
// }
// function sum() {
// return [].reduce.call(arguments, (a,b) => a+b)
// }
// function sum() {
// return [...arguments].reduce((a, b) => a + b)
// }
//
// console.log(sum(1, 2)); // NaN
// console.log(sum(1, 2, 3)); // 6
// console.log(sum(1, 2, 3, 4)); // Error
function Car() {
this.position = 0;
this.length = 2;
this['0'] = 4;
this['1'] = 5;
}
Car.prototype.drive = function (distance) {
console.log("I am driving");
this.position += distance;
}
function Person() {
this.position = 0;
}
Person.prototype.walk = function (distance) {
console.log("I am walking");
this.position += distance;
}
const car = new Car();
Person.prototype.walk.call(car, 10);
console.log([].reduce.call(car, (a,b) => a+b))
console.log(car);