1. // 对象字面量
    2. const bar = '345'
    3. const obj = {
    4. foo: 123,
    5. // bar: bar
    6. // 属性名与变量名相同,可以省略 : bar
    7. bar,
    8. // method1: function () {
    9. // console.log('method111')
    10. // }
    11. // 方法可以省略 : function
    12. method1 () {
    13. console.log('method111')
    14. // 这种方法就是普通的函数,同样影响 this 指向。
    15. console.log(this)
    16. },
    17. // Math.random(): 123 // 不允许
    18. // 通过 [] 让表达式的结果作为属性名
    19. [bar]: 123
    20. }
    21. obj[Math.random()] = 123
    22. console.log(obj)
    23. obj.method1()