Kendo Ui-class base class definition

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.