[英]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);
});
}
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.