开发者

In Firebug, $ == jQuery returns false, only sometimes

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.


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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜