Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 730
morgancodes Avatar asked Nov 05 '22 10:11

morgancodes


2 Answers

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

like image 69
johnjbarton Avatar answered Nov 12 '22 11:11

johnjbarton


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.

like image 34
Ishmael Avatar answered Nov 12 '22 11:11

Ishmael