您能否推荐以下哪些是最好的或它们的优缺点?我不确定,但也许,这取决于使用类型?一个在性能方面比另一个重(将课程保存在内存中等)?
提前致谢!
方法一
var MyClass = function(something) {
this.something = something;
}
MyClass.prototype = {
myMethod: function(arg) {
this.arg = arg;
return this.arg;
},
mySecondMethod: function() {
return "helloWorld";
}
}
方法二
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;
})();