1
    stages = {
            "1": {
                id: "1",
                div: "foo"
            },
            "2": {
                id: "2",
                div: "bar"
            },
            "3": {
                id: "3",
                div: "foobar"
            }
        };

When I run this in Firefox, it's fine. But when run in IE8, I get this error:

Message: Object doesn't support this property or method

Is this a known bug / is there a workaround or is it my syntax?

joedborg
  • 17,651
  • 32
  • 84
  • 118
  • 1
    Have you tried declaring "stages" with `var` ? – Pointy Oct 14 '11 at 15:51
  • No because I want it to be global – joedborg Oct 14 '11 at 15:54
  • 2
    I've run the above in IE8 and didn't get an error. Perhaps you just need to wrap you key parts (id, div) in "" as well? – scrappedcola Oct 14 '11 at 15:54
  • [And the line number is??](http://images.memegenerator.net/instances/400x/10617595.jpg) – Šime Vidas Oct 14 '11 at 15:56
  • 1
    Are you sure the error isn't coming from a different part of your code? – Abe Miessler Oct 14 '11 at 15:56
  • It's possible that IE is hiccuping on the use of a number as a property, try `stage1`, ... instead. – Brian Nickel Oct 14 '11 at 15:56
  • I think @Abe Miessler might be right, I've tried this in Jsfiddle and it seems to work on its own. It's just IE8 saying this line. – joedborg Oct 14 '11 at 15:58
  • Also, are you using `with` anywhere in the code? That can affect this kind of scoping. If you want to assign as a global variable `window.stages` would be more reliable. – Brian Nickel Oct 14 '11 at 15:58
  • Well actually keys of the object can't begin with a number. See: http://stackoverflow.com/questions/2026741/json-numeric-key – dfsq Oct 14 '11 at 15:59
  • dfsq - that link states that properties can begin with a number. It is just that you cannot use the "." notation to address that key. You have to use stages["1"] to address it. Identifiers cannot begin with a number so 1stages would be invalid but stages or stages1 would be valid. – scrappedcola Oct 14 '11 at 16:03
  • @dfsq that is not true - so long as they're quoted, as they are here, numbers are fine as keys. – Pointy Oct 14 '11 at 16:03
  • @jdborg if you want it to be global, declare it at the global level (with `var`) or write `window['stages'] = { .. };` – Pointy Oct 14 '11 at 16:04
  • Yep, that's how I was calling it anyway (stages["1"]) – joedborg Oct 14 '11 at 16:08

2 Answers2

3

If there is an element with id=stages in your markup, some browsers create global variable stages as a reference to it. However, IE doesn't support overriding it without declaring it. If you want stages variable to be global, put var stages; to global scope or assign the object to window.stages.

duri
  • 14,991
  • 3
  • 44
  • 49
0

I don't get that error at all. I can define that very code in a javascript file or in the console and it works just fine.

I do see that error if I try and run the code from jsfiddle.net. However the error is referring to code in Action.js and the following code

if (e && e.target.getParent().get('id') == 'm') {

It appears to be unhappy with e.target.

How exactly are you causing that error to popup?

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454