I'm pretty new to javascript and am wondering about quoting the keys in object shorthand
So I am using the OpenLayers js library and many of the object constructors take {options}
as the argument for setting different variables, callbacks, etc.
In my code I have a bunch of control objects which are used to manipulate the map and what-not
controls = {
navigation : new OpenLayers.Control.Navigation({'autoActivate' : false}),
zoom_out_box : new OpenLayers.Control.ZoomBox({
alwaysZoom : true,
out : true
}),
...
};
In some of their examples they use single quotes for the keys and others they won't {'ascending':false}
or {visibility: false}
.
I thought that maybe it had to do with reserved words or functions vs variables but I can add functions to my zoom box:
controls= {
zoom_out_box : new OpenLayers.Control.ZoomBox({
if : function(e){alert('blah');}
}),
zoom_out_box_2 : new OpenLayers.Control.ZoomBox({
'if' : function(e){alert('blah');}
})
};
I test it with an onlclick="controls.zoom_out_box.if(this)"
and it alerts fine and I get no warnings or errors in firebug.
So whats the difference in the quoting?