Repository navigation
Expand file tree
/
Copy pathfn-methods.js
More file actions
81 lines (61 loc) · 1.42 KB
/
Copy pathfn-methods.js
File metadata and controls
81 lines (61 loc) · 1.42 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* call и apply
*/
// const showThis = function (a, b, arr) {
// console.log(a, b, arr);
// console.log('showThis -> this', this);
// };
// showThis();
// const objA = {
// a: 5,
// b: 10,
// };
// showThis.call(objA, 5, 1, [100, 200, 300]);
// showThis.apply(objA, [5, 1, [100, 200, 300]]);
// const objB = {
// x: 788,
// y: 25,
// };
// showThis.call(objB, 1, 1, 2);
// showThis.apply(objB, [1, 1, 2]);
// showThis();
const changeColor = function (color) {
console.log('changeColor -> this', this);
this.color = color;
};
const hat = {
color: 'black',
};
// changeColor.call(hat, 'orange');
// console.log(hat);
const sweater = {
color: 'green',
};
// changeColor.call(sweater, 'blue');
// console.log(sweater);
/*
* bind
*/
const changeHatColor = changeColor.bind(hat);
const changeSweaterColor = changeColor.bind(sweater);
// changeHatColor('yellow');
// console.log(hat);
// changeSweaterColor('red');
// console.log(sweater);
const counter = {
value: 0,
increment(value) {
console.log('increment -> this', this);
this.value += value;
},
decrement(value) {
console.log('decrement -> this', this);
this.value -= value;
},
};
const updateCounter = function (value, operation) {
operation(value);
};
// updateCounter(10, counter.increment.bind(counter));
// updateCounter(5, counter.decrement.bind(counter));
// console.log(counter);