Better HN
topnewbestaskshowjobs
Log inSign up

schristo

8 karma · joined Dec 8, 2011 (14y ago) · 6 submissions

Software Engineer for www.thereitis.com
Submissions

comment 14y ago · link · parent

One more and then I'll shut up :)

It looks like my previous example was affected by eval.

The following reports foo's value as undefined while breaking for the debugger statement in Firefox and Chrome:

  (function () {
    var foo = "bar";
    return function() {
      debugger;
    };
  })()();
While the following reports foo's value as "bar" while breaking for the debugger statement:

  (function () {
    var foo = "bar";
    return function(_var) {
      debugger;
      return eval(_var);
    };
  })()('foo');

comment 14y ago · link · parent

So to answer myself, it does look like a reference is maintained despite no direct references existing within the inner function (unless eval is causing the reference to be maintained):

  (function () {
    var foo = "bar";
    return function(_var) {
      return eval(_var);
    }
  })()('foo');

comment 14y ago · link · parent

Maybe I'm missing something, but the function doesn't point to `el`. `el` just exists in a lower execution context on the stack. If a variable inside the anonymous function referenced `el` directly, then a closure would be formed over `el`. In this instance `this` is just assigned when the function is called.

comment 14y ago · link · parent

According to the article, the code below causes a memory leak in IE, though I fail to see how.

function addHandler() { var el = document.getElementById('el'); el.onclick = function() { this.style.backgroundColor = 'red'; } }

I'm assuming the author believes `this` is evaluated immediately and refers to the `el` variable instance, rather than being evaluated when the function is called.

Any ideas?

comment 14y ago · link · parent

It will currently fall back to using plain ol' HTML img tags, but Flash and WebGL renderers are in the works.

6.

Show HN: An immersive 3D interface for Facebook(apps.facebook.com ↗)

9 points · by schristo · 14y ago · 3 comments