• 原型继承


    if (typeof Object.create !== "function") {
        Object.create = function (o) {
            function F() {
            }
    
            F.prototype = o;
            return new F();
        }
    }
    
    
    var Model = {
        inherited:function () {
        },
        created:function () {
        },
    
        prototype:{
            init:function () {
            }
        },
    
        create:function () {
            //子类 返回一个新对象,继承自model对象,创建新模型
            var object = Object.create(this);
            //指向父类
            object.parent = this;
            //子类原型方法
            object.prototype = object.fn = Object.create(this.prototype);
    
            object.created();
            this.inherited(object);
            return object;
        },
    
        init:function () {
            //返回一个新对喜爱那个,继承自model.prototype -> model对象的一个实例
            var instance = Object.create(this.prototype);
            instance.parent = this;
            instance.init.apply(instance, arguments);
            return instance;
        }
    
    }
    
    var User = Model.create();
    var user = User.init();
    console.log(User ,user)

  • 相关阅读:
    mstsc远程桌面 mstsc /v:ip /admin
    JS模块化编程(五)---按照AMD规范扩展全局对象
    常见问题
    django--用户认证组件
    Django
    Django
    Django
    Django
    Django
    第六模块-图书管理系统--多表
  • 原文地址:https://www.cnblogs.com/aaronjs/p/2654342.html
Copyright © 2020-2023  润新知