【发布时间】:2017-03-05 10:49:34
【问题描述】:
是否可以根据条件扩展 Ember 类?像这样的:
A.reopen({
if (condition) {
init: function() {
this.super();
// some functionality
}.on('didInsertElement');
}
})
目前我有这样的模式:
A.reopen({
init: function() {
this.super();
if (condition) {
// some stuff
}
}.on('didInsertElement'),
cleanup: function() {
if (condition) {
// some stuff
}
}.on('willDestroyElement')
})
我猜我是否可以扩展 A 类,条件是我可以像这样简化我的模式:
A.reopen({
if (condition) {
init: function() {
this.super();
// some functionality
}.on('didInsertElement'),
clear_up: function() {
// some stuff
}.on('willDestroyElement')
}
})
插件中为discourse制作的所有类扩展
【问题讨论】:
-
为什么不切换第一行和第二行?您想重新开设什么课程以及您的用例是什么?
-
@Keo 我已经更新了问题以澄清我的情况
-
Keo 的回答对您没有帮助吗?
if (condition) { A.reopen({
标签: javascript class ember.js extends discourse