A great many letters have been typed regarding the number of letters in the
word "function".
What if we just made the keyword "function" entirely optional, dart-style?
*ShortNamedFunctionDeclaration* *:**Identifier **<no_linebreak>* *(* *
FormalParameterListopt* *) <no_linebreak> {* *FunctionBody* *}**
ShortNamedFunctionExpression* *:**Identifier **<no_linebreak>* *(* *
FormalParameterListopt* *) <no_linebreak> {* *FunctionBody* *}*Note that
the identifier is no longer optional, and that no linebreak is allowed
between the parameter list and the body, unlike current function decl/exprs.
myList.forEach(x (item) {
item += 2
doSomethingElse(item)
assert(typeof x === "function")
})
// expression, not declaration
assert(typeof x === "undefined")
// declaration, hoisted
assert(typeof doSomethingElse === "function")
doSomethingElse (item) {
// IIFE, not declaration
;(y (n) { item += n })(Math.random())
assert(typeof y === "undefined")
}
Is there an obvious case I'm overlooking where this sort of construction
would fail? Clearly, you can't put the { on the next line or else it'll be
interpreted as an invocation followed by a block, and that could be a
significant footgun. But, it's not a *new* footgun, since \n{ is
problematic with return anyhow. (I long for a mode where \n{ is always a
syntax error.) And, it introduces no new keywords, no syntax that isn't
already an error, and no new semantics.
I'm eager to see what I missed when you shoot this down :)
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss