I come from python where any class can have functions like __add__
, __str__
, ecc... to change the behavior of sum, printing, ecc... of the class.
Is there an equivalent in Javascript?
For example:
class A:
def __init__(self, a):
self.a = a
def __add__(self, other):
return self.a + other.a
How would this script be in javascript?