# 链式调用
# JQuery中 return this
function Item(num) {
this.value = num || 0
this.add = function (addNum) {
this.value += addNum
return this
}
this.sub = function (subNum) {
this.value -= subNum
return this
}
this.valueOf = function () {
console.log('valueOf')
return this.value
}
this.toString = function () {
console.log('toString')
return this.value + ''
}
}
let a = new Item(123)
alert(a.add(1).sub(2))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24