简体   繁体   English

使用Ember.js,如何在启动时收集与类组成的所有mixins?

[英]Using Ember.js, how do I gather all the mixins composed with a class at initiation time?

Exmaple of a class with three mixins: 具有三个mixins的类的示例:

Object = Ember.Object.extend( mixin1, mixin2, mixin3 {
                 init: function(){
                     this._super();
                     var myMixins = this.gatherMixins();
                 },

                 gatherMixins: function(){
                     // what goes in here?
                 }

 });

you can just do this: 您可以这样做:

gatherMixins: function() {
  Ember.Mixin.mixins(this).forEach(function (mixin) {
    Ember.Logger.log(mixin);
  });
}

Fiddle 小提琴

the following peace of code lists all properties of your mixins 下面的代码和平列出了mixins的所有属性

var mixinKeys = Ember.A();
Ember.Mixin.mixins(this).forEach(function (mixin) {
  Ember.Logger.log('mixin: ' + mixin.toString());     
  mixin.keys().forEach(function (key) {
    if (!mixinKeys.contains(key)) {
      mixinKeys.pushObject(key);
    }
  });
});
mixinKeys.forEach(function(key) {
  Ember.Logger.log(key);            
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM