craftyjs/Crafty — pull request #676 by kbrock (2014-01-01 02:39:36+00:00)
Title: Add unbinding by bind reference back

I'm new to craftyjs, and following through a great tutorial on http://buildnewgames.com/introduction-to-crafty/

While upgrading the tutorial to 0.6.1, the first 2 things that I've noticed that broken are:

1. The `animate`/`reel` portion of the code.
2. The `unbind` behavior on the victory page.

The `animate` code is well documented and trivial to track down and fix. Both due to the error messages as well as the clear documentation of the incompatibility.

The `unbind` code was more difficult to track down. It ate the error message (not saying it should be any different) and while #420 ( commit 35d9585caaf17315b ) said it was a rewrite, it highlighted removing the ability to `bind` to regular elements rather than global elements, not necessarily removing the `bind` reference functionality. This seems like a simple oversight and possibly wants to make its way back into the code.

Example of code that worked in the 0.5.x but not the 0.6.x branch:

```javascript
var ref = bind('KeyDown', function() { console.debug('x') });
unbind('KeyDown', ref)
```

The solution is quite easy, but I wonder if there is reason to break this.
working code:
```javascript
function printDebug() { console.debug('x'); }
bind('KeyDown', printDebug);
unbind('KeyDown', printDebug);
```

The alternatives are to document this change, or have `bind` return the command function passed in, so unbind will work unchanged.

If nothing else, I just wanted to document this changed behavior in an issue, so someone else coming along may be able to stumble upon the fix.

Thanks for the great library,
K