I\'m a JS dev, experimenting with functional programming ideas, and I\'m wondering if there\'s anyway to use chains for synchronous functions in the way the promise chains are w
You can set square
and num
as a property of square
call`
function square (num) {
if (!this.square) {
this.square = square;
this.num = num || 0;
};
if (num === undefined) {
this.num *= this.num
}
else if (!isNaN(num)) {
this.num *= num;
};
return this;
}
let foo = 2;
let c = new square(foo).square().square();
console.log(c.num);