[OpenLayers-Users] specifying options for OL class properties--when to use quotes?

Erik Uzureau euzuro at gmail.com
Thu Jul 24 19:07:02 EDT 2008


it was explained to me at some point in life that the "proper" JSON
notation was
putting quotes (single?) around the key names, ie:

var foo = { 'keyname': keyvalue };

...and I have been trying more or less to do that ever since. although
clearly it is
functionally equivalent to

var foo = { keyname: keyvalue };

(excepting where keyname is a js reserved word, as specified in eric
and cr5's responses)

...if the first one is "proper" for JSON, maybe it's proper for JS as well?

bottom line: it doesn't  matter.

e


On Wed, Jul 23, 2008 at 12:00 PM, Eric Lemoine <eric.c2c at gmail.com> wrote:
> Likewise you cannot do myobject.<key> if key is a reserved js word,
> you'll do myobject['<key>'] instead. Example: myobject['delete']
>
> Cheers. eric
>
> 2008/7/23, Christopher Schmidt <crschmidt at metacarta.com>:
>> On Wed, Jul 23, 2008 at 12:42:35PM -0400, Mike Quentel wrote:
>>> In some of the examples, when adding a Layer, I see some properties
>>> (options) have quotes (single or double).  What is the general rule for
>>> using quotes on the properties?
>>>
>>> Is this correct:
>>>
>>> {buffer: 2, gutter: 15, sphericalMercator: true, attribution: "some
>>> label"}
>>>
>>> or should it be this:
>>>
>>> {'buffer': 2, 'gutter': 15, 'sphericalMercator': true, 'attribution':
>>> "some label"}
>>
>> It makes no difference, except in a case here one of your 'keys' is a
>> javascript reserved word (like 'class' or 'function').
>>
>> Regards,
>> --
>> Christopher Schmidt
>> MetaCarta
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list