question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow reserved words for properties?

See original GitHub issue

Under Objects it says you shouldn’t use reserved words. I’m not sure this is important, though avoiding them might make sense for readability. At least using klass instead of class would seem wrong to me, as you are corrupting a word instead of finding a readable synonym (like type).

Right now you can use just about anything. E.g., test = {function: 1}; test.function === 1 –but additionally I think we can be confident this will continue to be the case. IndexedDB uses the method cursor.continue() which isn’t just a future-protected reserved word (like class) but a reserved word right now. But IndexedDB represents current API design by people involved in the standardization process.

I think it’s questionable from a readability point of view to use current keywords, but I don’t see any reason at all to avoid words reserved for possible future use (class and private, as used in the example, are both examples of that).

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Krinklecommented, May 15, 2015

Note that this isn’t an “IE bug”. It’s not supported in old IE because IE’s JScript engine correctly follows the ECMAScript 3 specification in this regard; which explicitly defines PropertyName as an Identifier, which is “an IdentifierName that is not a ReservedWord.

This was not by design, but at the time merely to document the status quo of different browsers and to ensure consistency. Other browser’s engines had this behaviour as well.

Since property names leave no ambiguity with other operators, this useless restriction was removed in ES5 where PropertyName has been redefined as a plain IdentifierName (https://es5.github.io/#x11.1.5). ES5 is still relatively new (not unlike CSS3 and HTML5) and first implemented in IE10 (almost in IE9), Firefox 4, Safari 6 and Chrome 19.

I’d recommend using something like JSHint (and set option es3: true), and also use it in your editor, to automatically catch these (and other things) ahead of time.

0reactions
goatslackercommented, May 15, 2015

Yeah this can be updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Workaround to allow reserved words to be used as property ...
I want to use class as a property name of an object, and access it using dot notation. Preamble. I already know that,...
Read more >
List of reserved words in Custom Property names
This article provides the list of Reserved Words that should not be used in Custom Property names. Customer will get an error for...
Read more >
JavaScript Reserved Words - W3Schools
JavaScript Reserved Words ; let*, long, native, new ; null, package, private, protected ; public, return, short, static.
Read more >
Solved: Naming a property with a reserved keyword for name
Solved: Hi all, I need to write a contract to act as a schema for the rest messages which a legacy system sends....
Read more >
Learn about Access reserved words and symbols
"Reserved words" are words and symbols that have a specific meaning to Microsoft Access. If you use a reserved word or symbol to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found