View Full Version : Object notation question.
jlizarraga
03-11-2009, 10:41 PM
Hi all,
Is there any difference between:
var object = {
name : "value"
};
and:
var object = {
"name" : "value"
};
?
Thanks!
No — but an unquoted name must be a valid identifier.
// These are equivalent:
({ foo: 5 });
({ 'foo' : 5 });
// But these are legal:
({ '1st' : 3 });
({ 'class' : 5 });
({ 'foo-bar' : 10 });
// While these are illegal:
({ 1st: 3 });
({ class: 5 });
({ foo-bar: 10 });
Master_script_maker
03-11-2009, 11:24 PM
Well the first is a more common practice, the second is more like defining array keys: var t=new Array("hi"=>5);, which is actually an object.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.