fat/bean — Issue #58: Idea: use replace() or similar to automatically preventDefault()
Author: djanowski
Created: 2012-02-08 19:10:17+00:00
State: open

Many times you want to 'replace' the default handler. You do so by calling `event.preventDefault()`. This could be DRYed up a bit by something like `replace()`, which automatically prevents the default handler. One big advantage would be that if the given handler fails, the default handler is still prevented (so for instance if you have a bug in your code which triggers an exception, a link is not followed, a form is not submitted, etc.)

Something like:

```javascript
replace: function(element, name, callback) {
add(element, name, function(event) {
try {
callback.apply(this, arguments);
}
finally {
event.preventDefault();
}
}
}
```

Thoughts?