Add operator “overloading”
Closed this issue · 1 comments
cshaa commented
The options
object should allow for methods like customAdd
and customGreaterThan
that would override the default action of these operators.
cshaa commented
In the actual implementation, I went with this API:
interface Options {
// ...
operators: {
'+': (a, b) => any,
'-': (a, b) => any,
// ...
}
}
The minus operator overload is used for both the binary and the unary operator:
-a
will result inoperators['-'](a)
a - b
will result inoperators['-'](a, b)
.
The modulo operator can be overloaded using operators['mod']
.