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'});
  • 相关阅读:
    组合模式
    装饰者模式
    桥接设计模式
    Docker介绍
    适配器模式
    设计软件下载
    17种设计字体的创意方法
    less编译(mac版gulp)
    50种常用快捷键整理
    WebStorm设置手机测试服务器-局域网内其他设备访问
  • 原文地址:https://www.cnblogs.com/greengnn/p/2408295.html
Copyright © 2011-2022 走看看