Hi, I am going to extend operators in the following manner:
export class Operator {
__add__(other: VecInterface) {
throw Error("__add__ not implemented yet!")
}
// $FlowFixType
[Symbol.for('+')] (other: any) {
return this.__add__(other)
}
__sub__(other: VecInterface) {
throw Error("__sub__ not implemented yet!")
}
// $FlowFixType
[Symbol.for('-')] (other: any) {
return this.__sub__(other)
}
}
// I use mixin because Point2D should inherit it from Geometry, and es6 is currently only supporting mono inheritance
mixin(Point2D.prototype, Operator.prototype) // like jquery `extend`
I tested it in runtime by executing
let a = new Point2D(1, 0)
let b = new Point2D(0, 1)
let c = a + b // VecInterface point to Vec2 or Vec3
But it add, and sub was not fired. Could you give me any suggestion about it?
Hi, I am going to extend operators in the following manner:
I tested it in runtime by executing
But it add, and sub was not fired. Could you give me any suggestion about it?