次のうち、どれが一番良いか、またはそれぞれの長所と短所を教えてください。よくわかりませんが、もしかしたら用途によるのでしょうか?パフォーマンスの点で、一方が他方よりも重いですか (クラスをメモリに保持するなど)?
前もって感謝します!
方法 1
var MyClass = function(something) {
this.something = something;
}
MyClass.prototype = {
myMethod: function(arg) {
this.arg = arg;
return this.arg;
},
mySecondMethod: function() {
return "helloWorld";
}
}
方法 2
var MyClass = (function () {
function MyClass(something) {
this.something = something;
}
MyClass.prototype.myMethod = function (arg) {
this.arg = arg;
return this.arg;
};
MyClass.prototype.mySecondMethod = function (arg) {
return "helloWorld";
}
return MyClass;
})();