谁能向我解释以下代码中发生了什么?我理解了 include() 和 exclude() 的含义,但是我们什么时候以及为什么要使用特定的函数呢?
var Class = function () {
var klass = function () {
this.init.apply(this, arguments);
};
klass.prototype.init = function () {};
klass.fn = klass.prototype;
//shortcut to access class
klass.fn.parent = klass; //where do we use it?
//adding class properties
klass.extend = function (obj) {
var extended = obj.extended; //what is happening here?
for (var i in obj) {
klass[i] = obj[i];
}
if (extended) extended(klass) //didn't understand this part
};
//adding instance properties
klass.include = function (obj) {
var included = obj.included; //??
for (var i in obj) {
klass.fn[i] = obj[i]; //??
}
if (included) included(klass) //??
};
return klass;
};
var Person = new Class; // is this same as: var Person = new Class();