15. 增强的对象字面量

  1. // 例子 15-1
  2.  
  3. // bad
  4. const something = 'y'
  5. const x = {
  6. something: something
  7. }
  8.  
  9. // good
  10. const something = 'y'
  11. const x = {
  12. something
  13. };

动态属性

  1. // 例子 15-2
  2.  
  3. const x = {
  4. ['a' + '_' + 'b']: 'z'
  5. }
  6.  
  7. console.log(x.a_b); // z