Fwd: three small proposals: the bikeshed cometh!

Garrett Smith dhtmlkitchen at gmail.com
Thu Apr 29 11:44:56 PDT 2010

---------- Forwarded message ----------
From: Garrett Smith <dhtmlkitchen at gmail.com>
Date: Thu, Apr 29, 2010 at 11:44 AM
Subject: Re: three small proposals: the bikeshed cometh!
To: Alex Russell <alex at dojotoolkit.org>

On Thu, Apr 29, 2010 at 3:01 AM, Alex Russell <alex at dojotoolkit.org> wrote:
> [ snip ]
>>> Many functions, both in the DOM and in the library, accept functions as
>>> arguments. ES5 provides a bind() method that can ease the use of these
>>> functions when the passed method comes from an object. This is, however,
>>> inconvenient. E.g.:
>>>  node.addEventListener("click", obj.method.bind(obj, ...));
>>> Also, insufficient. Event listeners can't be detached when using
>>> Function.prototype.bind:
>> That is not true at all. I suggest reading the ES5 specifation that
>> before proceeding.
> From
>   4. Let F be a new native ECMAScript object .
> I can't discern any particular reason why equivalence should succeed
> for multiple calls to bind() from the spec. What am I missing?

The bound function that is returned can be saved as a property of
something, so that it can be later removed.

var f = obj.method.bind(obj);
node.addEventListener("click", f, false);
node.removeEventListener("click", f, false);


More information about the es-discuss mailing list