If my site doesn’t require any sort of optimization and my object structure is fairly flat and so there is no need for inheritance, should I be using prototypes at all:
MyObject.prototype.<something>
I refer to this question Javascript when to use prototypes and various writings by John Resig who seems to focus on the performance values of prototype.
I find using the module pattern to define objects and their functions easier to read and manage and as michielvoo mentions, premature optimization tends to cause more harm than good.
Are there any other benefits or uses cases for prototype?
It’s a code organization pattern.
There are two good ways to share methods across objects
The only real advantage prototypes gives is that the link between
oneWayandbagOfMethodsis live.Having a live link allows really powerful extensions and monkey patching.
An example is
Object.prototype.methodNowLivesOnAllInstances = function () { };This is a way of doing “asynchronous” programming, you can extend the “class” without worrying whether all instances get the new method.
A note on the modular pattern, it’s bloated and not needed. Use a module builder like modul8 or browserify instead.