看看下面的代码::
Class.extend = function(prop) {
var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;
function Class() {
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.prototype.constructor = Class;
// why is this defined explicitly ?? i don't make sense to me ?
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
上面的代码是John Resig为一个名为spritz.js的插件使用的设计模式,现在代码中有这一行,见下文::
Class.prototype.constructor = Class;
这条线是什么?我不太明白。
构造函数确实需要显式设置吗?评论说明如下,
// Enforce the constructor to be what we expect
但是,如果没有添加该行,会产生什么影响呢?有人可以解释一下吗?