JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

11.5 Shorthand Functions

let nonblank = (l for (l in trimmed) if (l.length > 0 && l[0]!='#'));


11.5 Shorthand Functions

JavaScript 1.8 3 introduces a shorthand (called “expression closures”) for writing simple functions. If a function evaluates a single expression and returns its value, you can omit the return keyword and also the curly braces around the function body, and simply place the expression to be evaluated immediately after the argument list. Here are some examples:

let succ = function(x) x+1, yes = function() true, no = function() false;

This is simply a convenience: functions defined in this way behave exactly like functions defined with curly braces and the returnkeyword. This shorthand syntax is particularly convenient when passing functions to other functions, however. For example:

// Sort an array in reverse numerical order

data.sort(function(a,b) b-a);

// Define a function that returns the sum of the squares of an array of data let sumOfSquares = function(data) Array.reduce(Array.map(data, function(x) x*x), function(x,y) x+y);

3. Rhino does not implement this feature at the time of this writing.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/27690.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1