Object Literal Property Value Shorthand

前端 未结 2 387
悲&欢浪女
悲&欢浪女 2021-01-21 15:09

When creating JavaScript factory functions I was taught that the return syntax looks like the below:

function FF(constructorArg) {
   var _privateName = construc         


        
相关标签:
2条回答
  • 2021-01-21 15:37

    That's a shorthand syntax of defining object literal properties that was introduced by ECMAScript2015 (a.k.a. ES6). The only possible problem is environmental support. The environment should support this feature.

    For supporting ES5-based environments you can use an ES6 transpiler and convert the code into ES5.

    0 讨论(0)
  • 2021-01-21 15:58

    This is new es6 syntax. Only some browsers will support it unless you are compiling to es5. See the compatibility table: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer

    0 讨论(0)
提交回复
热议问题