Javascript + Firebug : "cannot access optimized closure" What does it mean?

closures, firebug, javascript, optimization

Solution

I had this issue too when Firebug is running.

It seems to happen sometimes, when an exception is raised (for whatever reason) and when there's a recursive function call somewhere in the call stack. The exception gets re-raised as the mysterious "InternalError: cannot access optimized closure"

Changing the way I define the recursive function, seems to make this issue go away. eg changing from

function foo(bar) {... foo(recursively); ...}

to

var foo = function(bar) {... foo(recursively); ...}

Hope that helps.

Problem

I just got the following error in a piece of javascript (in Firefox 3.5, with Firebug running) ``` cannot access optimized closure ``` I know, superficially, what caused the error. I had a line ``` options.length() ``` instead of ``` options.length ``` Fixing this bug, made the message go away. But I'm curious. What does this mean? What is an optimized closure? Is optimizing an enclosure something that the javascript interpretter does automatically? What does it do?

Original source