a => { return b <= 7; }
Sure you can write it without that, but only if you want to write willfully unclear code to annoy people, like writing an entire function body on one line. Just because you can do that doesn't mean that functions are inherently unclear.All of the examples that look confusing are artificially simple and doing things you wouldn't normally try to do.
If you're going to write it out, you might as well just add the `function` keyword for clarity because you're not saving a ton of keystrokes.
function(a) { return b <= 7; } var self = this;
foo(function(x) {
return x + self.y;
});
rather than: foo(x => x + this.y)
is so much less error-prone?If you miswrite "function" as "fnuction", you'll easily, quickly find out.
If you miswrite => as >= it might take ages to track it down.
If the function `foo` is defined as taking a function as its first argument (or even more precisely, a function which takes a number and returns a number), and you try to give it a boolean, then the static type checker will yell at you, and you'll just as easily find out as that fnuction typo.
People aren't kidding when they say Perl looks like line noise, but you get used to it and can find your way through even a dizzying regular expression with relative ease over time.
Yes, $s=~s+s+S+s+$s is valid Perl.
Suggesting that things like => are "too confusing" for JavaScript is to suggest that people that write JavaScript are too dumb to handle it. Is that what you're implying here?
Some programmers write in one language, but many write in several. Having the same shorthand available in JavaScript as in C# is a big deal, it makes things feel better. Being able to apply what you've learned in one domain directly to another is more efficient than having some ridiculously quirky JavaScript-only way of doing something.
That some people will abuse it or be confused is a problem that can be overcome with a little bit of learning. It's not a big deal.
EDIT: Now I got your point - you could accidentally assign a boolean value to a variable when you intended to create a function. One word - compile time type checking. Okay, four, Übersetzungszeittypprüfung in German.
Maybe I'm just getting old!