How to overload an operator ? #2937
Answered
by
dvd101x
srilakshmikanthanp
asked this question in
Q&A
-
Can I overload an operator like const add = (one, two) => {
if (typeof one === 'object' && typeof two === 'number') {
for (let key in obj) {
obj[key] += two;
}
}
// handle other cases ...
}
const getObject = () => {
return { one: 2, two: 2 }
}
evaluate(`getObject() + 2') // { one: 4, two: 4 } How do I put the overloaded add to the evaluator? |
Beta Was this translation helpful? Give feedback.
Answered by
dvd101x
Apr 18, 2023
Replies: 1 comment 2 replies
-
Or Can I implement a custom datatype to do the tasks, how to do it? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could import to your function a typed function with a new type signature.
Reference
https://mathjs.org/docs/core/extension.html