Kudos for this! It looks like a well-thought-out implementation which avoids the obvious gotchas and is mindful of the scoping/performance issues which plague other implementations[1], but I could never use it in a library or production code as it pollutes a native object (Function), which is considered a no-no in JavaScript.
Have you considered providing a functional interface as well/instead e.g.:
import overload from 'operator-overloading';
overload(() => {
let c1 = new Complex(1, 2);
let c2 = new Complex(3, 4);
assert.equal(c1 + c2, '4+6i');
})();
The method could still be enabled explicitly e.g.:
require('operator-overloading/global');
1 Although, surprisingly, this article suggests the performance hit isn't that large...
Kudos for this! It looks like a well-thought-out implementation which avoids the obvious gotchas and is mindful of the scoping/performance issues which plague other implementations[1], but I could never use it in a library or production code as it pollutes a native object (Function), which is considered a no-no in JavaScript.
Have you considered providing a functional interface as well/instead e.g.:
The method could still be enabled explicitly e.g.:
1 Although, surprisingly, this article suggests the performance hit isn't that large...