static functions used with prototype functions (js)

ref – https://stackoverflow.com/questions/1635116/javascript-class-method-vs-class-prototype-method

Yes, the first function has no relationship with an object instance of that constructor function, you can consider it like a ‘static method’.

In JavaScript functions are first-class objects, that means you can treat them just like any object, in this case, you are only adding a property to the function object.

The second function, as you are extending the constructor function prototype, it will be available to all the object instances created with the new keyword, and the context within that function (the this keyword) will refer to the actual object instance where you call it.

When MyClass.prototype.publicMethod can access ‘privileged’ members, it means you can access privileged properties and functions from constructor function.

When MyClass.prototype.publicMethod can access ‘public’ members, it means you can access public functions from the prototype, like so: