【发布时间】:2014-01-01 23:28:45
【问题描述】:
我正在使用这种类型的代码进行继承。问题是我在设置B 的prototype 时遇到错误,因为new A() 在设置B.prototype 时尝试访问params.param 和params 是undefined。如何处理?或者我应该使用另一种样式来模拟 js 中的继承?
function A(params) {
this.param = params.param; // this will throw error when set up B prototype
}
function B(params) {
A.call(this, params); // this is ok
}
B.prototype = new A(); // this is bad, A need some parameters
【问题讨论】:
标签: javascript