Defining a method by assigning a closure to a property of the receiver object in the constructor is inefficient, since a new closure is created for every instance. This wastes heap space and may interfere with JIT compilation.

Assign the function to a property of the prototype object instead. That way, all instances share the same closure.

In the following example, constructor Point defines method move by creating a new closure and storing it in the move property of each new instance. Consequently, p.move and q.move are different methods.

It is better to instead define move on the prototype object Point.prototype like this:

  • Mozilla Developer Network: Inheritance and the prototype chain.