Last active
September 27, 2022 15:48
-
-
Save bor0/ad90b5561e90c3d3bd9f11b8188996d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function computation() { | |
this.red_tree = []; | |
this.valid = true; | |
this.add = function (x, y) { | |
if (!this.valid) return; | |
var res; | |
if (typeof x != 'number' || typeof y != 'number') { | |
this.valid = false; | |
res = 'error'; | |
} else { | |
res = x+y; | |
} | |
this.red_tree.push( { | |
'op': 'add', | |
'x': x, | |
'y': y, | |
'res': res, | |
} ); | |
this.res = res; | |
} | |
return this; | |
} | |
var foo = computation(); | |
console.log(foo.red_tree); | |
console.log(foo.res); | |
foo.add(3,4); | |
console.log(foo.red_tree); | |
console.log(foo.res); | |
foo.add(3,'a'); | |
console.log(foo.red_tree); | |
console.log(foo.res); | |
/* | |
[] | |
undefined | |
[ { op: 'add', x: 3, y: 4, res: 7 } ] | |
7 | |
[ | |
{ op: 'add', x: 3, y: 4, res: 7 }, | |
{ op: 'add', x: 3, y: 'a', res: 'error' } | |
] | |
error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment