我想在打字稿中使用函数链.
考虑一堂课
export class numbOp(){
private n;
constructor(int num){
this.n = num;
}
public add(inc = 1){
this.n = this.n + inc;
}
}
我如何使用它(1)
let finalNumber = new numbOp(3);
console.log(finalNumber) // Output: 3
我如何使用它作为(2)
let finalNumber = new numbOp(3).add();
console.log(finalNumber) // Output: 4
我如何使用它作为(3)
let finalNumber = new numbOp(3).add().add();
console.log(finalNumber) // Output: 5
我如何使用它(4)
let finalNumber = new numbOp(3).add().add(2).toString();
console.log(finalNumber) // Output: "6"
Please, help me out to achieve this. Thanks in advance