zoukankan      html  css  js  c++  java
  • miniui中的继承

    引子:

    //ol0oOo : superclass
    //oO000O : constructor
    Olo01l = function() {
        Olo01l[ol0oOo][oO000O].apply(this, arguments)
    }
    ;

    这样的方法是什么呢?apply(this,arguments)是使用this对象来执行Olo01l["superclass"]["constructor"],arguments表示Function的局部变量,表示此方法传递的参数。如果想查询Object和Function的属性,可以在MDN:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments查看。

    那么superclass属性是什么时候被赋予的呢?Function可没有这个属性。

    来看看基类:

    //OlO10o : prototype
    //基类构造函数
    O010l0 = function() {
        this.o1o11l = {};
        this.uid = mini.newId(this.lo11);
        this._id = this.uid;
        if (!this.id)
            this.id = this.uid;
        mini.reg(this)
    }
    ;
    reg: function($) {
            this.components[$.id] = $;
            this.uids[$.uid] = $
        },
    //原型对象
    O010l0[OlO10o] = { isControl: true,id: null,lo11: "mini-", llOoo1: false,o0O1ol: true};
    ooo1l = O010l0[OlO10o];
    //赋予基类一些方法
    ooo1l[lO0llo] = O110;
    ooo1l[l1olO1] = o1o0l;
    ooo1l[lO00o1] = l00o0;
    ooo1l[oOl11] = l1o1O;
    ooo1l[O010OO] = O00Ol;
    ooo1l[O10lO0] = OOlOO;
    ooo1l[Olo1Oo] = oo0O0;
    ooo1l[lOlol0] = oooOo;

    reg方法是我从其他地方复制过来的。

    看到这边的时候我遇到的问题:

    1、var className = function(){} ;和function className(){}的区别。详解:https://www.cnblogs.com/alkq1989/p/5556771.html

    2、原型对象和原型链。这方面还是没整明白。

    3、js的构造函数。目前的认知是构造函数与普通function没太大区别,只是大多通过this来进行属性的赋值。

    之后通过对function[prototype]进行对原型对象进行方法的添加,之后看看怎么给派生类共享这些属性,以判断对应着继承机制中的哪一种,http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp

    接下来看第一个派生类:oo0OOl

    oo0OOl = function($) {    
      oo0OOl[
    'superclass']['constructor'].apply(this, arguments); this[lO10OO](); this.el.uid = this.uid; this[OO0l0l](); if (this._clearBorder) this.el.style.borderWidth = "0"; this[o1lOo](this.uiCls); this[l0lol](this.width); this[olO0O](this.height); this.el.style.display = this.visible ? this.O0l0 : "none"; if ($) mini.applyTo[Oloool](this, $) } ;
    OOOl(oo0OOl, O010l0, {jsName:
    null, "",height: "",visible: true,readOnly: false,enabled: true,tooltip: "",o0Ol1: "mini-readonly", lol101: "mini-disabled",name: "",_clearBorder: true,O0l0: "",ooOO: true,allowAnim: true,lo10: "mini-mask-loading", loadingMsg: "Loading...",contextMenu: null,ajaxData: null,ajaxType: "",ajaxOptions: null,dataField: "", tabIndex: 0 }); OOOl = function(A, D, C) {//A表示派生类,D:基类,C表示派生类添加到自己原型对象的一些属性 if (typeof D != "function") return this; var E = A , $ = E.prototype , B = D['prototype']; if (E['superclass'] == B)//如果 派生类的superclass属性 == 基类.prototype return; E['superclass'] = B; //否则就把基类的原型对象 赋值给 派生类的 superclass属性 E['superclass']['constructor'] = D;//将基类的原型对象的constructor指向基类构造函数,这样就可以通过调用O010l0['superclass']['constructor']来调用基类构造函数,再通过apply实现继
      //给派生类的prototype原型对象添加属
      for (var _ in B)//添加基类原型对象的属
        $[_] = B[_];
      if (C) //添加派生类自己预备想要拥有的属
        for (_ in C)
          $[_] = C[_];
      return E 
    }

    主要看一下OOOl方法,都写在注释上了。

    问题:都把属性通过循环赋值给派生类了,再调用基类构造函数是干什么?纯粹执行下方法?

    由此可见,这不是原型链的继承机制了,没有将基类的实例赋值给派生类的prototype属性。

    明天再看下吧。

    Good night.

  • 相关阅读:
    省选前模拟
    $SA$后缀数组
    一键运行
    多项式$fft$,$ntt$,$fwt$初步
    插头$DP$初步
    网络流初步
    欧拉路相关
    模板—Hash_map
    HZOJ Function
    HZOJ Tree
  • 原文地址:https://www.cnblogs.com/jianIsTheBest/p/11241346.html
Copyright © 2011-2022 走看看