【发布时间】:2012-10-31 20:33:51
【问题描述】:
这被认为是好的代码,有没有更清洁/更好的方法?所以子类对如何从存储机制中实际获取数据一无所知。只是能够使用这些方法来组合功能。
base.js
function Base() {}
Base.prototype.getInternal = function(id, cb) {}
module.exports = Base;
child.js
function Child() {}
util.inherits(Child, Base);
Child.prototype.get = function(id, cb) {
this.getInternal(id, cb);
}
module.exports = new Child();
test.js
var Child = require('child');
Child.get('id', function(err, result) {
});
【问题讨论】:
-
不是一个直接的答案.. 但上周的 Javascript 周刊通讯链接到一个关于 javascript 继承的好读物.. tobyho.com/2012/10/21/javascript-OO-without-constructors/…
标签: node.js inheritance prototype commonjs