如何在Javascript中使用Prototypes

时间:2013-08-16 11:41:00

标签: javascript oop prototype

我的下面代码有什么问题?我得到错误对象#没有方法'减去'。

function result() {

}
result.prototype.add = function (a,b) {
var sub = this.subtract(a,b);
}
result.prototype.subtract = function (a,b) {
return a-b;
}

module.exports = result;

1 个答案:

答案 0 :(得分:0)

快速猜测是调用new函数。

function result() {

}
result.prototype.add = function (a,b) {
   var sub = this.subtract(a,b);
}
result.prototype.subtract = function (a,b) {
   return a-b;
}

module.exports = new result();