morgancodes
morgancodes

Reputation: 25265

firebug is erroniously telling me my variable is not defined

I'm setting a breakpoint in the code below where it says "breakpoint". Also adding a watch expression for dataStore.

function(){
  var self = {};
  var dataStore = [];
  var areEq = UNAB.objectsAreEqual;

  self.put = function(key, value){
    /*breakpoint*/ dataStore.push({key:key, value:value});
  }
  return self;
}

At this breakpoint, Firebug tells me "ReferenceError: dataStore is not defined". Same results with trying to examine "areEq". However, dataStore.push executes without error. An additional strangness: adding a watch expression for "self" shows not the self object I expect, with one property, "put", but the "window" object.

Any idea what the heck is going on?

Upvotes: 5

Views: 927

Answers (2)

johnjbarton
johnjbarton

Reputation: 1857

I think this is a firefox bug. If you set a breakpoint on var dataStore = []; then continue, when hit the breakpoint in put(). you get a closure scope (in Firebug 1.6). That scope has dataStore and self. I think Firefox is optimizing the closure scope away, perhaps since the code is nonsense anyway: there is no way to access dataStore.

A complete test case will eventually appear at http://getfirebug.com/tests/script/stackoverflow/dataStoreIsNotDefined.html

see also https://developer.mozilla.org/en/DOM/window.self

Upvotes: 1

Ishmael
Ishmael

Reputation: 32540

Probably self is getting resolved by Firebug and probably also by Firefox in the global scope as referring to the current window. If you choose a different name other than "self", your code should make everyone happy.

Upvotes: 1

Related Questions