Comments (5)
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.
from javascript.
True.
This was one of those Airbnb specific things. We support IE8 and IE8 doesn't support reserved words as property names ([source](http://kangax.github.com/es5-compat-table/#Reserved words as property names)):
var obj = {
class: function(){}
};
// doesn't work in IE8
obj.class();
You can use them in IE8 if you use the subscript notation:
// this works
obj['class']();
but this contradicts our style guide preference of using dot notation to access properties by name and subscript notation to access properties by variable #properties.
This is another one of those preference decisions where it might sound like "you can't use reserved words as property names" but really what we're trying to say is "we would prefer if you didn't...for now".
Maybe it would be helpful to note what the reserved and future reserved words are and explain that they can be used as Identifiers but not as an IdentifierName ES5 #7.6.1 in [supporting browsers](http://kangax.github.com/es5-compat-table/#Reserved words as property names).
// SyntaxError: unexpected reserved word
function class(){}
from javascript.
This is also not supported in IE7, such as
var obj = {
default: 'this is default key',
private: 'OK',
class: 'this is class key'
};
The "default" and "class" key here does not work in IE7/IE8, but not for the "private" key
from javascript.
considering most people use Babel.js now (does Airbnb?), maybe this can be rescinded. It will automatically transpile aoeu.class
to aoeu['class']
from javascript.
Yeah this can be updated.
from javascript.
Related Issues (20)
- "semver" dep vulnerability HOT 1
- [spam]
- [spam]
- [spam]
- `import/no-unresolved` doesn't support package.json exports field HOT 1
- Style guide question: how to handle names with consecutive initialisms? HOT 2
- Deprecation of formatting rules HOT 3
- [spam]
- [spam] HOT 1
- [spam]
- [spam] HOT 1
- [spam]
- [spam]
- [spam]
- [spam]
- [spam]
- `defaultProps` is deprecated for functional components HOT 1
- [spam]
- [spam]
- Support Biome extends HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript.