我有下面的代码,看起来像下面这样:
var shared = {
create: function(){
//do stuff on create
}
}
enyo.kind(enyo.mixin({
name: "CustomInput",
//properties unique to input.
kind: enyo.Input
},shared));
enyo.kind(enyo.mixin({
name: "CustomTextArea",
//properties unique to input.
kind: enyo.TextArea
},shared));
enyo.kind(enyo.mixin({
name: "CustomSelect",
//properties unique to input.
kind: enyo.Select
},shared));我的同事告诉我,这是一种不正确的做事方式,可能会潜在地破坏一些东西,或者太令人困惑,因为他们从未见过以这种方式使用mixins。
我的问题是,这样做有什么错吗?
发布于 2013-06-21 09:08:13
如果你正在用混入扩展种类,这里有一个更新的方法来实现:
enyo.createMixin({
name: 'MyMixin',
mymethod: function() {
// do stuff
}
});
enyo.Control.extend({
mixins: ['MyMixin']
});这将在实例化之前将其混合在一起。如果您希望在运行时添加属性,请使用mixin()函数。
发布于 2013-04-21 00:04:26
如果它起作用了,那就没有错!然而,我不确定enyo.mixin有多深入,所以有时你可能得不到你所期望的一切。
https://stackoverflow.com/questions/16113377
复制相似问题