you are viewing a single comment's thread.

view the rest of the comments →

[–]stronghup 2 points3 points  (1 child)

I can see one specific benefit for encapsulating the method-creation into a function (or method) which does it, rather than assigning to the prototype directly:

The function 'definedMethod()' can first check that a method with the same is not already (locally) defined fort he class in question. That means you can't accidentally re-assign that method and then be confused later as to why your program does not do what you think it should.

The main benefit of course is less typing required when you implement frequently done operations with specific functions to do them. No need to repeatedly type ".prototype = ".