ES7 Array and Generator comprehensions
dibaiee.ir
dibaiee.ir
OTOH, block syntax (I don't think that's the correct term for it) has always irked me in JS, due to verbose function declaration, and no implicit return. So beautiful syntax in ruby like:
some_array.map { |el| el.length }
# Or the succinct version:
some_array.map(&:length)
Looks like this in JS: someArray.map(function() { return this.length; });
Now that ES6 has arrow functions with implicit returns, we can do this: someArray.map( s => s.length );
Since both comprehensions and implicit return functions are being released around the same time, I'll be interested to see which of the two gets more adoption. strings.map { |s| s.upcase }
is actually: strings.map() { |s| s.upcase }
...and this is what it's not: strings.map({ |s| s.upcase }) # Invalid
It's subtle, but it does make for a simpler, more readable syntax that lends itself to DSLs, since no parantheses are needed: validate :name { |name|
errors.add("Bad name") unless name
}
It's feasible in other languages, of course; Elixir, for example, introduces a Ruby-like "do" block syntax which is more regular than Ruby's. It might be too late for JavaScript, but I'm no parser expert.[1] Again, not sure of the correct term for this - functional style?
Does anyone know where the for..of syntax comes from? Just seems to deviate from the way that other languages represent comprehensions (including maths).
Why not keep JS simple (or better yet, simplify it further!) so that browser implementations might finally converge, and leave the syntactic niceties to preprocessors & compilers?
require('babel/register')
require('./main.js')
and carrying on like nothing ever happened.Apparently some people prefer to build a distribution of the entire project with Babel on deploy, which is fine, but it does cause an impedance mismatch with how projects are developed on the developer's machine; obviously both ways have to work.
A real problem with babel/register is the interface for including node modules, which I think needs improvement. You can't selectively include individual modules because the {only} option isn't additive, it replaces the default setting.
"browserify": {
"transform": [
"babelify"
]
}
...which is great, but Babel doesn't have anything like it for server-side stuff.