0

So, let's say I have a class:

class Dog {
    constructor(age){
        this.age = age;
    }
}

How do I make the Dog(7) * Dog(5) expression valid? Like, I want to write a function that would define the multiplication of this class (smth. like this):

Dog.operator["*"] = function(obj1, obj2){
    return obj1.age * obj2.age;
}

0 Answers0