An instance method could be added to this class in one of two ways, either inside the constructor or through the class prototype.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
However, it shouldn’t really be necessary to create an object to use the multiply or add method, since the method isn’t dependent on the state of the object for its execution. The method can be moved to the class to clean up this code a bit. First the class definition is created, which looks almost identical to the instance method declaration above, with the exception of the prototype keyword being removed:
1 2 3 4 5 6 7 8 9
Now the multiply method can be called through the class itself, instead of an instance of the class, like so: