---------- Forwarded message ---------- From: Garrett Smith <[email protected]> Date: Thu, Apr 29, 2010 at 11:44 AM Subject: Re: three small proposals: the bikeshed cometh! To: Alex Russell <[email protected]>
On Thu, Apr 29, 2010 at 3:01 AM, Alex Russell <[email protected]> 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 15.3.4.5: > > 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); Garrett _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

