craftyjs/Crafty — pull request #834 by starwed (2014-11-17 22:26:49+00:00)
Title: Autobind parameter for declaring components

Adds a special `autobind` role when creating components. This is a shorthand for binding functions to events, with the added benefit that they'll be automatically unbound when the component is removed or destroyed. You use it like this:

```
Crafty.c("MyComponent", {
autobind: {
EnterFrame: function(){
// this function is bound to EnterFrame
},
Moved: function(){
// this function is bound to the "Moved" event
},
// We can give a reference to a function instead!
Change: "_changeFunction"
},
_changeFunction: function(){
// This function is bound to "Change" by its name, but can still be called normally as a method on the component
}
});

```

I'd probably want to go through and switch some of the built-in components to use this (as well as `remove()`) at some point.