In kendo, using the prototype inheritance mechanism, class is the base class in Kendo, which defines the function extend used to derive other classes.
functionClass () {} class.extend=function(proto) {varBase =function() {}, member, that= This, Subclass= Proto && Proto.init? Proto.init:function() {that.apply ( This, arguments); }, FN; Base.prototype=That.prototype; FN= Subclass.fn = Subclass.prototype =Newbase (); for(MemberinchProto) { if(Proto[member]! =NULL&& Proto[member].constructor = = =Object) { //Merge Object membersFn[member] = Extend (true, {}, Base.prototype[member], Proto[member]); } Else{Fn[member]=Proto[member]; }} fn.constructor=Subclass; Subclass.extend=That.extend; returnSubclass; };
First, we can see
function Class () {}
That is, class is a function, in Kendo, all classes are defined by functions, and objects created using the new method are created.
function (Proto) {
The extend here is a static member of class, and in Kendo, derived subclasses are handled through the extend way of the parent class. The parameter of the method is a member object that is extended by the child class.
Inside this function, it is very strange to define a base class function base first, but it is very soon to be found that the prototype of this function is the same as the prototype of base, so the behavior pattern is the same as the object created by them.
var function function () { that.apply (this=new base ();
The subclass is defined by the INIT function, when the new subclass object instance is actually called the Init function that is provided when the subclass is defined, and the constructor of the parent class is called inside the init function of the subclass to implement the inheritance mechanism.
The prototype inheritance mechanism is implemented by setting the prototype of the subclass as an object instance of the parent class.
Subclasses always extend the members of the parent class, and the following code implements extending the various members for the child class's prototype object.
for inch Proto) { ifnull && proto[member].constructor = = = Object ) {// Merge Object members Fn[member] = Extend (true, {}, Base.prototype[member], Proto[member]); Else { = proto[member]; } }
The constructor property always points to the constructor that creates the current object. Here the constructor of the prototype object is also set to the subclass function. Ensure that you can work correctly when checking the type, you can see the instructions here: Javascript:constructor Property
Fn.constructor = subclass;
Makes subclasses also have an identical extend function, which facilitates the continuation of derived subclasses.
Subclass.extend = That.extend;
Finally, the subclass function is returned.
Kendo Ui-class base class definition