W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2011

Re: whether [Callback=FunctionOnly] should be the default

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 28 Jun 2011 18:53:18 -0400
Message-ID: <4E0A5B5E.4020403@mit.edu>
To: public-script-coord@w3.org
On 6/28/11 6:23 PM, Ian Hickson wrote:
> (function () {
>     var highlighted = false;
>     e.addEventListener("click", function (event) {
>       highlighted = !highlighted;
>       event.target.style.color = highlighted ? "red" : "black";
>     }, false);
> })();

This pattern doesn't work well if what you want is to encapsulate state 
including a given prototype chain and the like.  Sure, you can hack it 
all with a closure because you can just close over everything you care 
about and delegate things, but in some cases having an actual object 
which ends up as the this of the callback and has a useful prototype 
chain and whatnot is just much clearer.

-Boris
Received on Tuesday, 28 June 2011 22:53:47 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:03 UTC