【发布时间】:2012-01-30 18:32:25
【问题描述】:
我喜欢返回构造函数的模块模式,如下所述: http://elegantcode.com/2011/02/15/basic-javascript-part-10-the-module-pattern/
但是我不确定如何从使用此模式实现的对象继承。假设我有一个这样实现的父对象......
namespace('MINE');
MINE.parent = (function() {
// private funcs and vars here
// Public API - constructor
var Parent = function (coords) {
// ...do constructor stuff here
};
// Public API - prototype
Parent.prototype = {
constructor: Parent,
func1: function () { ... },
func2: function () { ... }
}
return Parent;
}());
如何定义一个子对象,它也使用从parent 继承的模块模式,以便我可以选择性地覆盖,例如func2?
【问题讨论】:
-
请注意,您提供的代码有一个错误——您将构造函数设置为
undefined。我已经编辑修复它。 -
我刚刚在这里stackoverflow.com/questions/16659326/…问了一个类似的问题-想知道您对此有何看法。
标签: javascript inheritance module design-patterns