0

I have an object that holds all my global variables and I'd to add a variable now, "position," that is itself an object. I tried

var g = {   
  var1: null,
  var2: null,
  position: {
    left: null, 
    top: null
  },
  var3: null
};

But this gives a compile error of:

SyntaxError: missing : after property id
position.left: null,

The idea is to be able to set position with

g.position.left = "200px";

Does anyone see the problem here?

holographic-principle
  • 19,688
  • 10
  • 46
  • 62
Steve
  • 4,534
  • 9
  • 52
  • 110
  • 3
    Cannot reproduce, check the error isn't coming from elsewhere (somewhere with a property named `id`) – Paul S. Jul 29 '13 at 23:49
  • 3
    Your error is being caused by code that you're not showing us – Eric Jul 29 '13 at 23:50
  • This code parses and runs just fine in Chrome. The error is most likely in the surrounding code. Could you post that? – JaredPar Jul 29 '13 at 23:50
  • Quotes around each property and it works at [jsoneditoronline](http://www.jsoneditoronline.org/) – krb686 Jul 29 '13 at 23:55
  • 2
    do you have `position.left: null,` anywhere in your code? – sabithpocker Jul 29 '13 at 23:58
  • JavaScript doesn't compile. – SomeShinyObject Jul 30 '13 at 00:02
  • Yes, you're right. Underneath what I showed you I had position.left: null. 'Sorry the problem wasn't more interesting but thanks for the extra eyes. – Steve Jul 30 '13 at 00:06
  • 2
    Regarding the comment "JavaScript doesn't compile" actually JavaScript is processed in two phases, a compile phase and then an interpret phase. See http://stackoverflow.com/questions/3887408/javascript-function-declaration-and-evaluation-order. – Steve Jul 30 '13 at 00:28

0 Answers0