ES6 getter/setter with arrow function

后端 未结 2 682
滥情空心
滥情空心 2020-12-28 11:20

I\'m using babel6 and for my pet project I\'m creating a wrapper for XMLHttpRequest, for the methods I can use:

open = (method, url, something) => {
  ret         


        
2条回答
  •  温柔的废话
    2020-12-28 11:55

    According to the ES2015 grammar, a property on an object literal can only be one of four things:

    PropertyDefinition:

    • IdentifierReference
    • PropertyName : AssignmentExpression
    • MethodDefinition

    The only one of these type that allows a leading get is MethodDefinition:

    MethodDefinition :

    • PropertyName ( StrictFormalParameters ) { FunctionBody }
    • GeneratorMethod
    • get PropertyName ( ) { FunctionBody }
    • set PropertyName ( PropertySetParameterList ) { FunctionBody }

    As you can see, the get form follows a very limited grammar that must be of the form

    get NAME () { BODY }
    

    The grammar does not allow functions of the form get NAME = ....

提交回复
热议问题