Copy Code code as follows:
var orchard = function () {//Base type constructor proxy static methods are all on the proxy function
This.constructor && this.constructor.apply (this,arguments);
};
Orchard.extend = function () {
var parentobj = this;
var parameters = Parentobj.parameters?
ParentObj.parameters.concat (_.toarray (arguments)): _.toarray (arguments);
var thisobj = function () {//Inheritance type constructor proxy
var newparameters = Parameters.concat (_.toarray (arguments));
This.constructor && this.constructor.apply (this,newparameters);
};
_.extend (Thisobj,parentobj);
_.extend (Thisobj.prototype,parentobj.prototype);
thisobj.parameters = parameters;
Thisobj.base = ThisObj.prototype.base = Parentobj; Proxy functions for base types
Thisobj.supper = ThisObj.prototype.supper = Parentobj.prototype; Constructor class members of the base type are all on the constructor
return thisobj;
};
Orchard.define = function (object) {
if (typeof object = = = "undefined") object = {Constructor:function () {}};
This.prototype = Object.constructor;
This.prototype.constructor = This.prototype;
for (var name in this.base)
if (typeof this[name] = = "undefined")
This[name] = This.base[name];
for (var name in This.supper)
if (typeof this.prototype[name] = = "undefined")
This.prototype[name] = This.supper[name];
for (var i = 0; i < arguments.length; i++)
_.extend (This.prototype,arguments[i]);
This.prototype.base = This.base;
This.prototype.supper = This.supper;
This.supper = undefined;
Delete This.supper;
return this;
};
Orchard.definenew = function () {
var newclass = This.extend ();
Return define.apply (newclass,arguments);
};
Call:
Copy Code code as follows:
var person = orchard.definenew ({
Constructor:function (name) {
THIS.name = name;
},
Say:function () {return "Hello, I ' m" + name;}
});
var Aben = person.extend ("Aben");
Aben.define ({
Constructor:function () {
This.supper.apply (this,arguments);
}
});
var aben = new Aben ();
Alert (Aben.say ());
The idea is this, the code has not been validated. The idea of sharing, everyone to see To do. haha ~ ~