Infrequently Noted

Alex Russell on browsers, standards, and the process of progress.

Comments for JS 1.8 Function Expressions: The Opposite of "Good"

Unclear what is being proposed, other than just another name for `function`. If that is all, I wonder how that would be implemented in reality. Certainly you couldn't get rid of `function` completely ... backwards compatibility with the interwebs, books, editors... It should be clear that the mixing that would occur, within single "scripts" and in general would be quite confusing, esp. to the new programmer. And if you write non-trivial code, there's something to be said for being able to scan this fat code and easily pick out the functions -- big, unmistakable words that clearly state what is going on (notwithstanding following sentence). Something (less wordy) but equivalent to ThisIsAConstructor() might be useful, as that is a real issue with the language.
by nataxia at
According to the language designers, function !== lambda. If you haven't seen this yet, here is potentially what you're looking for I assume:

by TNO at
I think that "function" should be the first one to go. "return" is probably the next. That's why I campaigned for different styles for lambdas, or function expressions, or whatever the name du jour is.
I hope you didn't overlook the fact that it makes the return statement implicit as well.

This discussion may be relevant:

by TNO at
Nope! I didn't overlook it. Implicit returns are a good feature for any lambda syntax, but I was just sort of assuming that *every* lambda proposal would come complete with implicit return. Under that assumption, I think the critique holds.
by alex at
I understand the function != lambda argument, it's just wrong = )
by alex at
The really big WTF is when you find yourself accepting the "terse" syntax because, well, it is a bit more terse, and then run into this scenario:

function ()

Of course, what can clearly be inferred is that I am defining an anonymous function that returns an empty object literal. Oh wait, that's just a function with no body, returning nothing.

Now of course, since the parser does not read the {} as an object literal here, this is invalid syntax altogether:

function ()

So in the end, you have to fall back to:

function () { return { a: 0 } }

So yeah, I would pick a different preamble syntax for anonymous functions to eliminate the parser ambiguity.

"function" is unwanted, and so is "return". Both just add noise.

In some cases, the word "return" doubles the length of the function body. e.g. in ruby, compare: {|i| i>3 }.map

with {|i| return i>3 }.map

I agree with you 100% on this one. They should just get rid of function expressions and implement what you suggested.
by cypherpunk at
If the next version of ES allows backward incompatibility:

fun - as a stripped down lambda-esque function. (x) x + 2 - as shorthand for fun(x)

by kevin c at