Search code examples
javascripthashobject-literal

Why does my "next" property disappear in my JavaScript hash in Firefox 3.6


I'm creating a hash as an options object to pass to a jQuery plugin. One of the keys I need to use, as defined by the plugin, is next.

This works fine in Safari (so I assume Webkit in general) but in Firefox its removed, or ignored or something... its just not there. For example:

var opts = {
  "next": "some selector string",
  "prev": "some other selector string",
  "anotherOption": 1
};

console.log(opts);

Ouput:

anotherOption      1
prev               "some other selector string"

It's driving me crazy. What's more, there are tons of plugins and things that use this key name in some sort of options hash and I have never noticed this behavior before. Can anyone tell me what is going on here and how to work around it? (I've tried doing opts.next = "something" instead but it yields the same result).

It also not an issue with the surrounding code - I've typed the example (minus the console.log call) into my Firebug console and gotten the same result.


Solution

  • The next property does not print out in Firebug console, but it is indeed defined. This may be a problem with Firebug, not JS. Your code should still work.

    >>> var v = {};
    undefined
    >>> v.next = 'foo';
    "foo"
    >>> v.prev = 'bar';
    "bar"
    >>> v
    Object { prev="bar"}
    >>> v.next
    "foo"