javascript - Is the 'catch' method name of JS Promises/A+ invalid since it's a JS keyword? -
i started use js promises in project recently. noticed every time use .catch
js linter complains. run , should looked ecmascript spec , looks right: since catch
keyword can not used identifier. understand method names identifiers, invalid:
promise.reject("duh").catch(alert);
it should instead:
promise.reject("duh")['catch'](alert);
what missing?
what missing?
a property name not identifier, can use identifier name. spec on property accessors:
memberexpression : memberexpression . identifiername callexpression : callexpression . identifiername
and identifiers:
identifier :: identifiername not reservedword
you can use arbitrary identifer name (but not things integers) in dot property access, can't use [reserved] keywords identifier, e.g. in variable or function name.
however, did change es5, in ecmascript 3 property names required identiers. that's why still need use bracket notation keywords if want support legacy browsers; , it's reason why linter complains it. same holds property names in object literals.
Comments
Post a Comment