Assuming points are represented using JavaScript Array as [x,y], how could I define the + operator on points such that:
[1,2] + [5,10] == [6,12]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JavaScript does not have a facility for overriding the built-in arithmetic operators.
There are some limited tricks you can pull by overriding the
.valueOf()and.toString()methods, but I can’t imagine how you could do what you’re asking.You could of course write a function to do it.