views:

102

answers:

4

Okay, I have this weird problem in Firefox. I type in Firebug's console

$ == jQuery

Sometime it displays true, and sometimes false. The file is just an empty HTML document with one script tag including jQuery. I refresh the page, click "Run" in the console, and again, occasionally it returns true, occasionally false.

On the occasions where it returns false, $.toString() gives

function anonymous() {
    return window.console.notifyFirebug(arguments, "$", "firebugExecuteCommand");
}

Now here's the weird thing. When $ == jQuery gives false using Firebug's console, if I go to the address bar and type javascript:alert($ == jQuery);, it alerts true!

Does anyone have any idea what's going on here? It's (occasionally) messing up my debugging.

A: 

Maybe firebug is using $ for something and there´s a race condition between jquery and firebug for setting that variable, you have to consider that a lot of javascript libraries use that variable name, if I´m not wrong prototype is one of them

jaime
A: 

You should be using instanceof instead of an equality check.

For the reason why it us likely that firebug have defined $ in a local scope.

balupton
A: 

There could be many other things using $ as a function/variable symbol. jQuery is just one of them. Firebug is probably overriding $.

F.Z
+3  A: 

There's a native function defined by firebug that assigns $ to getElementById. I don't think you can resolve this "bug" without upgrading to a newer version of Firebug which potentially eliminated the issue, or manually assign $ = jQuery.

It's probably come as a result of possibly jQuery already being cached and the Firebug $ overriding it as it fires too fast, or vice versa.. just some weird bug in regards to speed of assignment + caching.

meder