我正在尝试确定声明 javascript“类”使用的辅助函数的最佳实践是什么。例如:
方法#1:
// closure issues?
function helper(param) {
return compute(param);
}
function HeavilyInstantiated() {}
HeavilyInstantiated.prototype.computeHard = function(params) {
var someResult = helper(params.prop1);
return someResult;
}
方法#2:
function HeavilyInstantiated() {}
// still, only one instance for all objects instantiated?
HeavilyInstantiated.prototype.helper = function(param) {
return compute(param);
}
HeavilyInstantiated.prototype.computeHard = function(params) {
var someResult = this.helper(params.prop1);
return someResult;
}