私は、各操作(add、multなど)のメソッドを持つこのRationalクラスを持っています
function Rational(nominator, denominator){
this.nominator = nominator;
this.denominator = denominator || 1;
}
Rational.prototype = {
mult: function(that) {
return new Rational(
this.nominator * that.nominator,
this.denominator * that.denominator
);
},
print: function() {
return this.nominator + '/' + this.denominator;
}
};
var a = new Rational(1,2),
b = new Rational(3);
console.log( a.mult(b).print() ); // 3/2
たとえば、有効にするなど、より「自然」にすることはできconsole.log( a * b )
ますか?