0
How to program an operator on Javascript?
To make the sum of 2 object you must create an operator function, how to do it in Javascript?
6 odpowiedzi
+ 19
operator overloading not supported in JavaScript....
+ 18
summ = [];
function Sum(val) {
summ.push(this);
this.val = val;
this.sum = function() {
var sm = 0;
summ.forEach(function(va) {
sm += va.val;
});
return sm;
}//sum
}//Sum
new Sum(5);
new Sum(6);
alert(summ[1].sum());
+ 16
function sum(a,b) {
return a+b;
}//sum
alert(sum(3,2));
+ 1
Thanks :(
0
I know that.
For example : I create class 'complex' then declare 2 complex objects z1 and z2.
I want to be able to make the sum of this 2 object like this z3=z1+z2
0
Is not what I'm looking for!
This is example in c++
https://code.sololearn.com/c0A1ODBNCJRT/?ref=app