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'});
  • 相关阅读:
    Scala集合
    Spark常用算子
    Flink运行架构
    Flink 有状态的算子和应用程序
    Flink 状态一致性
    Flink 检查点(checkpoint)
    Flink 时间语义与watermark
    Flume的可靠性保证:故障转移、负载均衡
    Hive 文件存储格式
    BPM与OA区别
  • 原文地址:https://www.cnblogs.com/greengnn/p/2408295.html
Copyright © 2011-2022 走看看