emberjs重写补充类之reopen方法和reopenClass方法
生活随笔
收集整理的這篇文章主要介紹了
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 endsay: function(thing) {this._super(thing + "!"); } });
正如你所見,reopen是用來為實例添加屬性和方法的。而當你需要創建類的方法或為類本身添加屬性時,則可使用reopenClass。
Person.reopenClass({createMan: function() {return Person.create({isMan: true}) } }); Person.createMan().get('isMan') // true Person類的createMan方法用來創建Person類的一個實例
轉載于:https://www.cnblogs.com/toward-the-sun/p/4095462.html
總結
以上是生活随笔為你收集整理的emberjs重写补充类之reopen方法和reopenClass方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android模拟器启动没有拨号功能
- 下一篇: 我的记忆,我的年