Improving Function.prototype.bind
Andrea Giammarchi
andrea.giammarchi at gmail.com
Mon Jan 9 16:09:34 PST 2012
just to make it more concrete for those interested:
http://webreflection.blogspot.com/2012/01/introducing-objecthandler.html
IDL Like description and code ... to me this is a much faster/easier/better
solution than Function#bind ... unshimmable for IE < 9 but ... you know,
some wrapper could do the trick in any case.
/**
* interface ObjectHandler implements EventListener {
* void handleEvent(in Event evt);
* void remitEvent(in Event evt);
* attribute Object events;
* };
*
* @link
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventListener
*/
var ObjectHandler = {
handleEvent: function handleEvent(e) {
var
events = this.events,
type = e.type
;
if (events.hasOwnProperty(type)) {
events[type].call(this, e);
}
},
remitEvent: function cancelEvent(e) {
e.currentTarget.removeEventListener(
e.type, this, e.eventPhase === e.CAPTURING_PHASE
);
}
};
Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120110/edbf3603/attachment.html>
More information about the es-discuss
mailing list