Concise Function Body
From where is this produced? It's unsound if from MemberExpression (ES1-5) or PrimaryExpression (ES6) -> FunctionExpression -> ... ConciseBody.
I'm pretty sure there was some discussion about this on some thread, but it may have been fleeting...
Concise methods (harmony:concise_object_literal_extensions#methods ) have been proposals for quite some time.
When I added ArrowFunctions into the draft, it seemed to make sense to consistently apply them to the other new function definition form (concise methods) that we already had added. Once that was done, it also made sense, from a consistency standpoint, to permit them for get/set properties.
This means there is a simple rule: function definition using the keyword function always have a bracketed body. All other forms of function definition use ConciseBody which allows for either an assignment expression or a bracketed body.
I'm happy to debate this if there is any disagreement, that's why we have spec. drafts. Nothing is set in stone.
Allen
On May 14, 2012, at 9:31 AM, Erik Arvidsson wrote:
The latest ES6 draft introduced the notion of a concise function body and it is being used for arrow functions as well as for methods and set/get accessors.
Grammar:
ConciseBody : [lookahead does not include { ] AssignmentExpression { FunctionBody }
Example:
var object = { get x() this._x, set x(v) this._x = v, method() this._x };
I don't remember us ever discussing this change?
Personally I think it makes things more consistent since concise function bodies are allowed in ArrowFunction but I've heard people complain about it already.
p.s. Allen, the spec draft has a bunch of ConsiseBody typos.
all fixed...
On May 14, 2012, at 9:53 AM, Brendan Eich wrote:
From where is this produced? It's unsound if from MemberExpression (ES1-5) or PrimaryExpression (ES6) -> FunctionExpression -> ... ConciseBody.
AssignmentExpression : ... ArrowFunction
ArrowFunction : ArrowParameter => ConciseBody
The latest ES6 draft introduced the notion of a concise function body and it is being used for arrow functions as well as for methods and set/get accessors.
Grammar:
ConciseBody : [lookahead does not include { ] AssignmentExpression { FunctionBody }
Example:
var object = { get x() this._x, set x(v) this._x = v, method() this._x };
I don't remember us ever discussing this change?
Personally I think it makes things more consistent since concise function bodies are allowed in ArrowFunction but I've heard people complain about it already.
p.s. Allen, the spec draft has a bunch of ConsiseBody typos.