zoukankan      html  css  js  c++  java
  • emberjs重写补充类之reopen方法和reopenClass方法

    无需一次性将类定义完全,你可以使用reopen方法来重新打开(reopen)一个类并为其定义新的属性。

    Person.reopen({
      isPerson: true
    });
    Person.create().get('isPerson') // true

    当使用reopen时,你也同样可以覆写已经存在的方法并调用this._super

    Person.reopen({
      // override `say` to add an ! at the end
      say: function(thing) {
        this._super(thing + "!");
      }
    });

    正如你所见,reopen是用来为实例添加属性和方法的。而当你需要创建类的方法或为类本身添加属性时,则可使用reopenClass

    Person.reopenClass({
      createMan: function() {
        return Person.create({isMan: true})
      }
    });
    Person.createMan().get('isMan') // true Person类的createMan方法用来创建Person类的一个实例
  • 相关阅读:
    python面向对象开发
    python迭代器和生成器
    python 集合
    python 字典
    python 元组
    python列表
    python字符串方法
    dom节点操作
    vue 跨域配置代理 get/post 请求
    Vuecli版本调整
  • 原文地址:https://www.cnblogs.com/toward-the-sun/p/4095462.html
Copyright © 2011-2022 走看看