Giter VIP home page Giter VIP logo

Comments (5)

Krinkle avatar Krinkle commented on May 7, 2024 1

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.

hshoff avatar hshoff commented on May 7, 2024

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.

jackchen83 avatar jackchen83 commented on May 7, 2024

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.

rstacruz avatar rstacruz commented on May 7, 2024

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.

goatslacker avatar goatslacker commented on May 7, 2024

Yeah this can be updated.

from javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.