来自 Google 的 Closure 库:
goog.inherits = function(childCtor, parentCtor) {
/** @constructor */
function tempCtor() {};
tempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor();
/** @override */
childCtor.prototype.constructor = childCtor;
};
创建的临时构造函数有什么好处?
代码不只是这样的原因是否有:
goog.inherits = function(childCtor, parentCtor) {
/** @constructor */
childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new parentCtor();
/** @override */
childCtor.prototype.constructor = childCtor;
};