Passing arguments to the create() function?

Is it possible to pass arguments to the create() function of an enyo kind? If so, how do I do it?

Comments

  • The create() method is passed in the properties object that gets passed to the new KindConstructor call. You can pull items out of that property object before you call this.inherited to change the way you work if you want. However, there's no support for additional parameters beyond that one object.
  • (longer explanation i had already typed before i saw Ben's response ...)

    You normally don't call create() in your code. It's called by the framework during construction. Checkout enyo.kind.makeCtor and Component.constructed for details.

    In enyo 2.2:

    create doesn't receive anything as arguments

    In the nightly build:

    The argument passed to create is the property hash passed to the constructor when the instance is created.

    So, if you're creating the kind like this
    new MyKind({arg1:true});
    create will receive the object {arg1:true} as it's parameter.

    Similarly, if you define an instance within the components[] like this:
    components: [
        {kind:"MyKind", arg1:true}
    ]
    create will receive the same thing (plus a few additional properties injected by the framework).

    In either case:

    Anything in the hash passed to the constructor and anything specified in the component definition in the components[] will be set on the kind when it's created and is accessible via this.XXX. So in the examples above, you could use this.arg1 to get the provided value from within methods on MyKind.

    Example
  • ah, didn't realize this was a 2.2/nightly difference, thanks @theryanduffy
  • Ah, I see how it works now. Thanks guys.
Sign In or Register to comment.