Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at
Mon Jan 9 00:18:43 PST 2012

I would be more than happy to go on with "libraries first" approach as long
as we don't have to wait 6 years before a needed feature is going to be

I have also raised the problem because it is in my opinion underestimated
but mainly because I would like to avoid the fragmentation of
implementations that Function#bind had indeed in its past.

My proposal was more like: would an Object.prototype.boundTo method make
If in this discussion list the outcome would be "Yes, it does" then me and
other libraries author may already consider, at least, the proposal, and
implement the best way they want with or without WeakMap shims in the

If the answer is "No, bind should never be objects matter" then I could
come up with different proposal as long as we agree on a solution that
could be considered in TC39 too.

As summary, I am trying to find a "direction" able to solve this problem.
Even an interface, as common implementation independent direction, would be
fine ... something based on handleEvent property, another pattern rarely
seen out there, but with clear idea of how the whole problem would be
solved ... example:

// does not have to be in the global Object, just saying
Object.prototype.handleEvent = function handleEvent(evt) {
  // if there is some standard/agreed way to invoke meant method ...
  // let's use this pattern ...
  this["onEvent" + evt.type.slice(0, 1).toUpperCase() +

// let's say that if the object is an object
// no need to implement handleEvent
// because everything is handled automagically
// behind the scene ...
window.addEventListener("resize", {
  onEventResize: function (evt) {
    window.removeEventListener(evt.type, this, false);
}, false);

So that if handleEvent is not explicit, the onEvent + event.type will be
fired ... I am not sure it's clear what I mean ... but this would be
another proposal I'd like to hear feedbacks about

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list