简体   繁体   中英

What is this es6 syntax called?

I am relatively new to es6. I came across the following syntax and can't figure out what is it called.

let parameter = 'key1'; 
const obj = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3',
  }[parameter];

That concept is not specific to ES6.

That's just an object, out of which you're getting 1 value, depending on the parameter .

It is similar to:

let parameter = 'key1'; 
const temp = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3',
}
const obj = temp[parameter];

Except temp is never declared.

Statement 1: variable declaration and definition.

Statement 2: variable declaration, inline object definition and accessing it using an indexer .

FYI: your code is plain old JavaScript. Only the const and let keywords are ECMAScript 6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM