0

I have the following code, that looks like the following:

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));

I'm being informed by my peers that this is an incorrect way of doing things, and could potentionally break something, or be too confusing because they've never seen mixins used in this way.

My question is, is there anything wrong with doing this, in this way?

mach
  • 8,315
  • 3
  • 33
  • 51

2 Answers2

1

If you are extending kinds with mixins, here is a newer way to do this:

enyo.createMixin({
    name: 'MyMixin',
    mymethod: function() {
        // do stuff
    }
});

enyo.Control.extend({
     mixins: ['MyMixin']
});

This will mix it in before instantiation. If you wish to add properties at a run time, use mixin() funciton.

Lex Podgorny
  • 2,598
  • 1
  • 23
  • 40
0

If it works, it's not wrong! However, I'm not sure how deep enyo.mixin goes, so you may not be getting everything you expect sometimes.

Webby Vanderhack
  • 889
  • 7
  • 13
  • According to their documentation, which is what I'm aware will happen, properties of the right assigned object will take precedence over the left. So as long as whoever is looking at the code understands that, I didn't think it would ever be a problem. – user1816425 Apr 23 '13 at 19:36