es6写法:
class Man {
constructor(state) {
this.num = state;
}
add(number) {
this.num += number
return this;
}
minus(number) {
this.num -= number
return this;
}
};
const man = new Man(123).add(10).minus(100);
es5写法:
function gen(val) {
this.number = val
}
gen.prototype.add = function (number) {
this.number += number
console.log(this.number)
return this
}
gen.prototype.minus = function (number) {
this.number -= number
console.log(this.number)
return this
}
let func = new gen(123)
new gen(123).add(123).minus(200)