- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Tue, 28 Jun 2011 18:53:18 -0400
- 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