代码拉取完成,页面将自动刷新
var Class = function(parent) {
var klass = function() {
this.init.apply(this, arguments);
}
// 继承
if (parent) {
var subclass = function() {};
subclass.prototype = parent.prototype;
klass.prototype = new subclass();
}
// klass.prototype.init = function() {}
klass.fn = klass.prototype;
klass.fn.parent = klass;
// 上下文代理
klass.proxy = function(callback) {
var self = this;
return (function() {
return callback.apply(self, arguments);
})
}
klass.fn.proxy = klass.proxy;
// 类扩展
klass.extend = function(obj) {
var extended = obj.extended;
for (var i in obj) {
klass[i] = obj[i];
}
if (extended) {
extended(klass);
}
}
// 实例扩展
klass.include = function(obj) {
var included = obj.included;
for (var i in obj) {
klass.fn[i] = obj[i];
}
if (included) {
included(klass);
}
}
return klass;
};
// example
var Person = new Class();
Person.prototype.init = function() {
//code here
}
Person.extend({
find: function() {},
exists: function() {}
});
Person.include({
save: function() {},
destroy: function() {}
});
Person.find();
var p1 = new Person();
p1.save();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。