zoukankan      html  css  js  c++  java
  • backbone.js的类继承骨干代码qwrap实现

    var Model = function(opt){
    this._config(opt);
    this.init.apply(this,arguments);
    }
    QW.ObjectH.mix(Model.prototype,{
    init : function(){},
    _config : function(opt){
    var opt = opt||{};
    QW.ObjectH.mix(this,opt,true);
    },
    attrs : {},
    get : function(key){
    if (this.attr.hasOwnProperty(key)) {
    return this.attr[key];
    }
    return null;
    },
    set : function(key,val,override){
    if(override){
    this.attr[key] = val;
    }else{
    if (!this.attr.hasOwnProperty(key)) {
    this.attr[key] = val;
    }
    }
    }
    });


    var extend = function(proto, props){
    var child = inherits(this, proto, props);
    child.extend = this.extend;
    return child;
    };
    var inherits = function(p,proto, props){
    var child;
    if (proto && proto.hasOwnProperty('constructor')) {
    child = proto.constructor;
    } else {
    child = function(){ p.apply(this, arguments); };
    }
    function ctor(){};
    ctor.prototype = p.prototype;

    child.prototype = new ctor;
    child.prototype.constructor = child;

    if(proto){
    QW.ObjectH.mix(child.prototype,proto,true);
    }
    if(props){
    QW.ObjectH.mix(child,props,true);
    }
    child.__super__ = p.prototype;
    return child;
    };
    Model.extend = extend;
    var app = {};
    app.model = Model.extend({
    init : function(){
    alert(1);
    }
    });
    app.model2 = app.model.extend({
    init : function(){
    alert(2);
    }
    });
    var _app = new app.model2({test:'test'});
  • 相关阅读:
    AJAX请求头Content-type
    原 layer父子页面交互
    layer.closeAll()无法关闭弹窗的解决办法之一
    成员函数的重载,覆盖与隐藏
    const限定符用法汇总
    构造函数和析构函数的调用时机
    MFC 消息映射、分派和传递
    C++对象模型
    函数指针与虚函数表
    数据类型与内存映像
  • 原文地址:https://www.cnblogs.com/greengnn/p/2408295.html
Copyright © 2011-2022 走看看