functionadd(a, b) { functionadd(a, b) { if(typeof a === "undefined") throwError("function should have at least 1 arguments"); b ? result = a + b: result += a; } var result = 0; add(a, b); return tmp = { add: function (a, b) { add(a, b); returnthis; }, toString: function () { return result; } } } console.log(""+add(1, 2).add(3));