Re: Firefox and Firebug show different script result?

64 views
Skip to first unread message
Message has been deleted
Message has been deleted

Sebastian Zartner

unread,
Mar 19, 2013, 5:43:55 PM3/19/13
to fir...@googlegroups.com
Executing isArray([2,4,6]) via Firebug's Command Line using Firefox 19.0.2 + Firebug 1.11.2 on WinXP correctly returns true. So I suggest you update your browser and Firebug to the current versions and try it again.
Also note that you can use Array.isArray() instead to check whether a variable is an array, which is supported by all current browsers.

Sebastian

On Monday, March 18, 2013 5:13:08 PM UTC-5, bucephalus org wrote:
Hi there,

I might have overlooked something trivial, but I can't figure out what it is and I am really stuck with my programs, due to some strange behaviour.
Consider the following HTML file

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">
  <script type="text/javascript">
    function isArray(x) { return (x.constructor && x.constructor === Array); }
  </script>
</head>
<body>
  <h1> <code>[2,4,6]</code> is an array? </h1>
  <script>
    document.write(isArray([2,4,6]));
  </script>
</body>
</html>

When I open this file in Firefox (15.0.1 Firefox for Linux Mint, mint - 1.0), it shows:

[2,4,6] ist ein Array?

true

and that is what I would expect.

But when I open the Firebug (version 1.10.6) console, the input of
  isArray([2,4,6])
returns
  false

This is strange, especially since the input of
  [2,4,6].constructor && [2,4,6].constructor === Array
returns
  true

Why does it return different results for isArray([2,4,6]) in Firefox and Firebug?

Thank you in advance,
Thomas

bucephalus org

unread,
Mar 20, 2013, 2:30:54 AM3/20/13
to fir...@googlegroups.com
Hi Sebastian,
thank you for your help and response.


On Tuesday, March 19, 2013 10:43:55 PM UTC+1, Sebastian Zartner wrote:
Executing isArray([2,4,6]) via Firebug's Command Line using Firefox 19.0.2 + Firebug 1.11.2 on WinXP correctly returns true. So I suggest you update your browser and Firebug to the current versions and try it again.

I only work with Linux, but I probably should try to update things now. I already changed to testing things with node.js in the meantime, which evaluates correctly, as well.
What really troubles me and what I can't seem to grasp is the fact that the results are actually different. Firebug always uses the same JavaScript engine as Firefox, doesn't it?

 
Also note that you can use Array.isArray() instead to check whether a variable is an array, which is supported by all current browsers.

This is a good idea, I didn't know and didn't think of that. 

Thank you, again
Cheers Thomas 

Sebastian Zartner

unread,
Mar 21, 2013, 8:39:34 AM3/21/13
to fir...@googlegroups.com
Hi Thomas,


Firebug always uses the same JavaScript engine as Firefox, doesn't it?
Of course it does.


What really troubles me and what I can't seem to grasp is the fact that the results are actually different.
I don't know if Simon Lindholm's comment to this actually reached you, so I post it again:

The Web Console, on the other hand, does have this behavior, and it is a consequence of how it evaluates JS: everything is evaluated within *a different global object* than "window". In particular, the Web Console's Array and []-type objects aren't the same as the page's, so e.g. "Array === window.Array" and "isArray([])" would test false there. See also https://bugzilla.mozilla.org/show_bug.cgi?id=690529.
Please note the "Web Console" is the Firefox internal console + command line, which you can open via Ctrl+Shift+K.

Sebastian

bucephalus org

unread,
Mar 25, 2013, 5:50:11 PM3/25/13
to fir...@googlegroups.com
Hi Sebastian,

thank you, once more.
I am still a newbie in this JavaScript universe, but I think I slowly get the idea.

Because the behavior of Firebug was so odd (in the sense of my problem), I already started to use node.js as my development environment. But Firebug is much more comfortable in this respect, and I intend to understand it better.

Anyway, thank you very much, again.

Cheers, Thomas


Sebastian
Reply all
Reply to author
Forward
0 new messages