Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which of these prototype declarations is better and why? [duplicate]

I'm trying to decide how to set up my functions in the prototype for my main library.

Should I use:

Library.prototype.funcA = function () {.....};
Library.prototype.fucnB = function () {.....};
etc..

or

Library.prototype = {
    funcA: function () {.....},
    funcB: function () {.....},
    etc..
};

So basically the first choice adds all my functions to the prototype. The second option replaces the prototype with an object containing all my functions. Does it matter?

like image 621
ciso Avatar asked Mar 10 '14 18:03

ciso


1 Answers

I would go with the first option.

You don't want to completely replace the prototype, as you never know what has been added from another project.

If it's something completely self-contained that only you are working on, the second is an ok option. But it is still not a good habit to get into so you don't inadvertently blow away some functionality something else is counting on.

like image 139
krillgar Avatar answered Sep 30 '22 16:09

krillgar