Mozilla.com

  1. Using Object Initializers
Table of contents
No headers

If the property (lval) happens to be a JavaScript keyword, you can quote it such as:

 var params = {'for':"screen"};

This was needed as Opera reserves the keyword 'goto', and this would not work:

 var params = {goto:"parent"};

where the solution is:

 var params = {'goto':"parent"};
I addressed this in the article, so hopefully that'll clear up any confusion people might have. Also, note that ECMAScript 4 will allow keyword-named property names, so whenever other browsers get around to allowing this it'll become less of an issue. --Waldo 01:16, 9 August 2007 (PDT)

Page last modified 08:16, 9 Aug 2007 by Waldo

Tags:

Files (0)