Skip to content

Instantly share code, notes, and snippets.

@mbuttler
Last active August 29, 2015 14:22
Show Gist options
  • Save mbuttler/0a79371ccc1b90280f82 to your computer and use it in GitHub Desktop.
Save mbuttler/0a79371ccc1b90280f82 to your computer and use it in GitHub Desktop.
Matt's Javascript Question of the Day
// behold, an object.
var neutralFolk = {};
// when I go to check this, I get an "unexpected token ." syntax error. Why?
var enemies = {
enemies.khan = {};
enemies.salazar = {};
};
// my understanding is that I should be able to define my object properties
// within the curly braces that set the ememies object up... know what I mean?
// just to prove I'm not a complete fool, it DOES pass when I use a new object Constructor.
var friends = new Object();
{
friends.bill = {};
friends.steve = {};
};
// so what am I doing wrong in the enemies object? I want to know how to do this without needing a new object
// constructor when I create a new object. Shouldn't I just be able to shorthand define it?
@mbuttler
Copy link
Author

mbuttler commented Jun 1, 2015

@dfmcphee
Copy link

dfmcphee commented Jun 1, 2015

Should be like this:

var enemies = {
  khan: {},
  salazar: {}
};

@mbuttler
Copy link
Author

mbuttler commented Jun 1, 2015

@dfmcphee Thanks, man!

@dfmcphee
Copy link

dfmcphee commented Jun 1, 2015

No problem 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment