-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectChaining.js
54 lines (46 loc) · 1 KB
/
objectChaining.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
45
46
47
48
49
50
51
52
53
54
const A = {
x: function() {
console.log("x")
return this;
},
y: function() {
console.log("y")
return this;
},
z: function() {
console.log("z")
return this;
}
}
A.x().y().z();
// let calc = {
// total: 0,
// add: function(a) {
// this.total += a;
// return this;
// },
// subtract: function(a) {
// this.total -= a
// return this;
// },
// multiply: function(a) {
// this.total *= a
// return this;
// }
// }
// const result = calc.add(10).multiply(5).subtract(30).add(10);
// console.log("calc result", result.total)
function $(el) {
return {
css: function(propertyName, value) {
el.style[propertyName] = value
return this;
}
};
}
const ele = { style: {} }; // document.createElement('p')
const a = $(ele);
a.css('color', '#fff')
.css('backgroundColor', '#000')
.css('fontWeight', 'bold');
console.log("ele", ele)