标签云

微信群

扫码加入我们

WeChat QR Code

Consider the following code (taken from mdn):var a = ["Hydrogen","Helium","Lithium","Beryl­lium"];var a2 = a.map(function(s){ return s.length });var a3 = a.map( s => s.length );Is it possible to make it even shorter? E.g.:var a4 = a.map( .length );The above doesn't work (it results in a SyntaxError: Unexpected token .).So is there any way to do that in ES2015?


I hope not. The syntax is just wrong.

2019年04月20日12分39秒

No. 12 more to go...

2019年04月19日12分39秒

no, you cannot.

2019年04月19日12分39秒

Why would you even want to do that other than golfing? It makes it much harder to read what's going on.

2019年04月19日12分39秒

There's a difference of 4 characters. I don't understand the point of the question.

2019年04月20日12分39秒

Destructuring is nice, however it's 7 characters longer than the a3 example

2019年04月20日12分39秒