Setting handlers after creation


Basically when you create an enyo Control you specify handlers this way:

name: "MyKind",
components: [
{name: "myControl", content: "my content", ontap: "myHandler"}

myHandler: function(inSender, inEvent) {
alert("myControl tapped!");
But is it possible to affect handler after the control has been created, like this:
    this.$.myControl.ontap = enyo.bind(this, this.myHandler)
Of course this doesn't work, but is there any similar way to do this using enyo?


  • You're close! The handler declarations expect a string rather than a function reference. So this works. That said, IMO changing the handler at runtime would make for less maintainable code than using a static handler that dynamically routes to a different function.
  • Yes, I currently use this method, but the thing is that the function I want to use as a handler isn't part of the enyo kind.

    I wrap enyo in a MVC component system with enyo kinds being views. The handler accesses to the model so it is in the controller component (out of the enyo kind), so I can't affect a string to 'ontap'.

    But I guess I'll stick to "static handler that dynamically routes to a different function", thanks anyways ;)
  • Couple other options ...

    You could override dispatchEvent:
    You could assign the bound function to the owning kind:

  • Actually the second method you gave is what I'm doing. Except `doStuff` is set outside of the kind, just after I've created an instance of it in my controller.

    Thanks for the help ;)
Sign In or Register to comment.