oop - What's the recommended way to declare fields of a class in JavaScript? -
Is it better to declare fields of a class like this:
function myclass () {This.aMethod =} function () {// code}}
or such a way:
function myClass () {} MyClass .prototype Prototype method, because it is more efficient because it adds function for prototype, which means that the constructor Any object created with it automatically gets that method While the methods of pre / first way should be prepared for every little thing that you do different.
Although in reality it depends on the method that you are doing with the law. If you do not need this public method, you can choose options from the this.method
or function statement.
Comments
Post a Comment