w3future.com

Sjoerd Visscher's weblog

Last Update

10/20/2005; 10:56:34 PM

Try XHTML 2.0
Src XHTML 2.0
RDF Metadata


Site Colors

Syn Atom 1.0
Syn RSS 0.91
Syn Subscribe

CC Licensed
Geo URL
With Radio

Thursday, October 20, 2005

Leak Free Javascript Closures

If you're confused about how closures in JavaScript cause memory leaks in Internet Explorer, this is for you: Leak Free Javascript Closures. Then, without leakage, you can write code like this:

function attach()
{
  var element = document.getElementById("my-element");
  element.attachEvent("onclick", function()
    {
      alert("Clicked: " + this.innerHTML);
    }.closure(element));
}

Also if you want to do something like this: setTimeout(obj.method, 1000), and you find out that inside the method this is not obj, you can now do this: setTimeout(obj.method.closure(obj), 1000) to fix it.