Object Literal Property Value Shorthand

前端 未结 2 415
悲&欢浪女
悲&欢浪女 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.

提交回复
热议问题