Home>

The other day, when I posted a question about how to determine a flag, we suggested a variety of writing methods.
[js] I want to branch processing by the contents of an array

One of them is the following.

const operations = {
  FFFFF () {console.log ('[F, F, F, F, F] processing');},
  FFFFT () {console.log ('[F, F, F, F, T] processing');},
  / * ・ ・ ・ * /
  TFTFT () {console.log ('[T, F, T, F, T] processing');},
  / * ・ ・ ・ * /
  TTTTT () {console.log ('[T, T, T, T, T] processing');},
};
const sampleAry = ["T", "F", "T", "F", "T"];
Operations [sampleAry.join ('')] ();// =>"[T, F, T, F, T] processing" is output.

Now I'm studying by writing each of the codes proposed at that time.

':'is missing.

I get the error

.
Line of FFFFF ().

Looking at the error explanation in detail, it says that "the colon between the second and third operands of the ternary conditional operator cannot be omitted".
Is this a ternary conditional operator in the first place?
Isn't it an array?

And how can I handle this error in ie11?

I asked a question because I was wondering.

  • Answer # 1

    IE11 doesn't work with most ES2015 code.
    The only existence is that it works if let and const.
    http://kangax.github.io/compat-table/es6/

    const operations = {
      FFFFF () {console.log ('[F, F, F, F, F] processing');},
      FFFFT () {console.log ('[F, F, F, F, T] processing');},
      / * ・ ・ ・ * /
      TFTFT () {console.log ('[T, F, T, F, T] processing');},
      / * ・ ・ ・ * /
      TTTTT () {console.log ('[T, T, T, T, T] processing');},
    };

    This code is recommended by ES2015, which is the JS specification document.
    I found it from the writing method that became able to write newly by the writing method of the object corresponding to the browser.
    shorthand methods

    ES2015 has appeared after the browser called IE11. Of course, this writing is not supported.
    For some reason, IE11 supports only let and const, and it may be the most advanced at that time ...

    If you are writing in ES5, use a writing method that creates ordinary objects.
    (For ES5 compliance,varis used for variable declarations, andfunction () {}is used because there is no arrow function.)

    var operations = {
      FFFFF: function () {console.log ('[F, F, F, F, F] processing');},
      FFFFT: function () {console.log ('[F, F, F, F, T] processing');},
      / * ・ ・ ・ * /
      TFTFT: function () {console.log ('[T, F, T, F, T] processing');},
      / * ・ ・ ・ * /
      TTTTT: function () {console.log ('[T, T, T, T, T] processing');}
    };

  • Answer # 2

    Unintentional code.
    Probably

    const operations = {
      FFFFF: function () {console.log ('[F, F, F, F, F] processing');},
      FFFFT: function () {console.log ('[F, F, F, F, T] processing');},
      / * ・ ・ ・ * /
      TFTFT: function () {console.log ('[T, F, T, F, T] processing');},
      / * ・ ・ ・ * /
      TTTTT: function () {console.log ('[T, T, T, T, T] processing');},
    };

  • Answer # 3

    This is the method definition syntax (MDN) introduced in ES6.

    Although it is also in the table below, of course IE11 is not supported.