Skip to content

How to overload an operator ? #2937

Answered by dvd101x
srilakshmikanthanp asked this question in Q&A
Discussion options

You must be logged in to vote

You could import to your function a typed function with a new type signature.

math.import(
    {
        add: math.typed(
            {
                'Object, number': (obj, num) => {
                    for (key in obj){
                        obj[key] += num
                    }
                    return obj
                }
            }
        )
    }
)

Reference

https://mathjs.org/docs/core/extension.html

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@dvd101x
Comment options

dvd101x Apr 18, 2023
Collaborator Sponsor

Answer selected by josdejong
@dvd101x
Comment options

dvd101x Apr 18, 2023
Collaborator Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants