Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
144
6
callbackFunction(
new
Date());
console.log('Ending callYouBack()');
}
运行这段代码,点击按钮后你会看到如下的输出。
About to call callYouBack()
Starting callYouBack()
Logging at: 2:20:59 PM
Ending callYouBack()
All finished
6.1.4
参考
6.2
节介绍可以简化匿名函数声明的句法,这种句法特别适合声明返回一个值的单行
函数。表
5-1
列出了一些重要的
Array
方法,接受函数为参数。
6.2
使用箭头函数
6.2.1
问题
你想使用
JavaScript
箭头句法,以尽可能紧凑的方式声明行内函数。
6.2.2
方案
近年来,
JavaScript
越来越强调函数式编程模式,数组处理和异步
promise
是两个最
明显的例证。为此,
JavaScript
增加了一种简化行内函数编写的新句法,叫作箭头句法。
下面的示例使用
Array.map()
法变换一个数组的内容,其中用到一个具名函数,
没有使用箭头句法。原数组是一组数字,变换后的数组包含各个数的平方。
const
numbers = [1,2,3,4,5,6,7,8,9,10];
function
squareNumber(number) {
return
number**2;
}
函数
145
const
squares = numbers.map(squareNumber);
console.log(squares); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov
JavaScript

JavaScript

David Flanagan
JavaScript

JavaScript

T. J. Crowder

Publisher Resources

ISBN: 9787519869601