没有合适的资源?快使用搜索试试~ 我知道了~
首页Eloquent JavaScript 3rd Edition (True PDF)
Eloquent JavaScript 3rd Edition (True PDF)
需积分: 10 67 浏览量
更新于2023-05-25
评论
收藏 2.16MB PDF 举报
Eloquent JavaScript, 3rd Edition: A Modern Introduction to Programming (True PDF)
资源详情
资源评论
资源推荐


Eloquent JavaScript
3rd edition
Marijn Haverbeke

Copyright © 2018 by Marijn Haverbeke
This work is licensed under a Creative Commons attribution-noncommercial
license (http://creativecommons.org/licenses/by-nc/3.0/). All code in the
book may also be considered licensed under an MIT license (http://opensource.
org/licenses/MIT).
The illustrations are contributed by various artists: Cover and chapter illus-
trations by Madalina Tantareanu. Pixel art in Chapters 7 and 16 by Antonio
Perdomo Pastor. Regular expression diagrams in Chapter 9 generated with
regexper.com by Je Avallone. Village photograph in Chapter 11 by Fabrice
Creuzot. Game concept for Chapter 15 by Thomas Palef.
The third edition of Eloquent JavaScript was made possible by 325 nancial
backers.
You can buy a print version of this book, with an extra bonus chapter included,
printed by No Starch Press at http://a-fwd.com/com=marijhaver-20&asin-
com=1593279507.
i

Contents
Introduction 1
On programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why language matters . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Code, and what to do with it . . . . . . . . . . . . . . . . . . . . . . . 7
Overview of this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1 Values, Types, and Operators 10
Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Boolean values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Empty values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Automatic type conversion . . . . . . . . . . . . . . . . . . . . . . . . . 18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2 Program Structure 22
Expressions and statements . . . . . . . . . . . . . . . . . . . . . . . . 22
Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Binding names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
The environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The console.log function . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Return values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Control ow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
while and do loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Indenting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Breaking Out of a Loop . . . . . . . . . . . . . . . . . . . . . . . . . . 33
ii

Updating bindings succinctly . . . . . . . . . . . . . . . . . . . . . . . 34
Dispatching on a value with switch . . . . . . . . . . . . . . . . . . . . 34
Capitalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3 Functions 39
Dening a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Bindings and scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Functions as values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Declaration notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Arrow functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
The call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Optional Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Growing functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Functions and side eects . . . . . . . . . . . . . . . . . . . . . . . . . 54
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4 Data Structures: Objects and Arrays 57
The weresquirrel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Data sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Mutability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The lycanthrope’s log . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Computing correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Array loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
The nal analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Further arrayology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Strings and their properties . . . . . . . . . . . . . . . . . . . . . . . . 72
Rest parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
The Math object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Destructuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
iii
剩余447页未读,继续阅读











安全验证
文档复制为VIP权益,开通VIP直接复制

评论0