Ebook Speaking JavaScript

Speaking JavaScript
Speaking JavaScript

Download

THÔNG TIN TÀI LIỆU

Nhà xuất bản O’Reilly Media, Inc
Tác giả Axel Rauschmayer
Số trang 460
Ngày xuất bản 2014
File PDF

NỘI DUNG TÀI LIỆU
Part I. JavaScript Quick Start
1. Basic JavaScript
Background 3
Syntax 4
Variables and Assignment 6
Values 7
Booleans 12
Numbers 14
Operators 15
Strings 15
Statements 16
Functions 18
Exception Handling 21
Strict Mode 21
Variable Scoping and Closures 22
Objects and Constructors 24
Arrays 28
Regular Expressions 31
Math 31
Other Functionality of the Standard Library 32

Part II. Background
2. Why JavaScript?
Is JavaScript Freely Available? 35
Is JavaScript Elegant? 35
Is JavaScript Useful? 36
Does JavaScript Have Good Tools? 37
Is JavaScript Fast Enough? 37
Is JavaScript Widely Used? 37
Does JavaScript Have a Future? 38
Conclusion 38

3. The Nature of JavaScript
Quirks and Unorthodox Features 40
Elegant Parts 40
Influences 41

4. How JavaScript Was Created
5. Standardization: ECMAScript
6. Historical JavaScript Milestones

Part III. JavaScript in Depth
7. JavaScript’s Syntax
An Overview of the Syntax 53
Comments 54
Expressions Versus Statements 54
Control Flow Statements and Blocks 57
Rules for Using Semicolons 57
Legal Identifiers 60
Invoking Methods on Number Literals 62
Strict Mode 62

8. Values
JavaScript’s Type System 67
Primitive Values Versus Objects 69
Primitive Values 69
Objects 70
undefined and null 71
Wrapper Objects for Primitives 75
Type Coercion 77

9. Operators
Operators and Objects 81
Assignment Operators 81
Equality Operators: === Versus == 83
Ordering Operators 87
The Plus Operator (+) 88
Operators for Booleans and Numbers 89
Special Operators 89
Categorizing Values via typeof and instanceof 92
Object Operators 95

10. Booleans
Converting to Boolean 97
Logical Operators 99
Equality Operators, Ordering Operators 102
The Function Boolean 102

11. Numbers
Number Literals 103
Converting to Number 104
Special Number Values 106
The Internal Representation of Numbers 111
Handling Rounding Errors 112
Integers in JavaScript 114
Converting to Integer 117
Arithmetic Operators 122
Bitwise Operators 124
The Function Number 127
Number Constructor Properties 128
Number Prototype Methods 128
Functions for Numbers 131
Sources for This Chapter 132

12. Strings
String Literals 133
Escaping in String Literals 134
Character Access 135
Converting to String 135
Comparing Strings 136
Concatenating Strings 137
The Function String 138
String Constructor Method 138
String Instance Property length 139
String Prototype Methods 139

13. Statements
Declaring and Assigning Variables 145
The Bodies of Loops and Conditionals 145
Loops 146
Conditionals 150
The with Statement 153
The debugger Statement 155

14. Exception Handling
What Is Exception Handling? 157
Exception Handling in JavaScript 158
Error Constructors 161
Stack Traces 162
Implementing Your Own Error Constructor 163

15. Functions
The Three Roles of Functions in JavaScript 165
Terminology: “Parameter” Versus “Argument” 166
Defining Functions 166
Hoisting 168
The Name of a Function 169
Which Is Better: A Function Declaration or a Function Expression? 169
More Control over Function Calls: call(), apply(), and bind() 170
Handling Missing or Extra Parameters 171
Named Parameters 176

16. Variables: Scopes, Environments, and Closures
Declaring a Variable 179
Background: Static Versus Dynamic 179
Background: The Scope of a Variable 180
Variables Are Function-Scoped 181
Variable Declarations Are Hoisted 182
Introducing a New Scope via an IIFE 183
Global Variables 186
The Global Object 187
Environments: Managing Variables 190
Closures: Functions Stay Connected to Their Birth Scopes 193

17. Objects and Inheritance
Layer 1: Single Objects 197
Converting Any Value to an Object 203
this as an Implicit Parameter of Functions and Methods 204
Layer 2: The Prototype Relationship Between Objects 211
Iteration and Detection of Properties 217
Best Practices: Iterating over Own Properties 220
Accessors (Getters and Setters) 221
Property Attributes and Property Descriptors 222
Protecting Objects 229
Layer 3: Constructors—Factories for Instances 231
Data in Prototype Properties 241
Keeping Data Private 244
Layer 4: Inheritance Between Constructors 251
Methods of All Objects 257
Generic Methods: Borrowing Methods from Prototypes 260
Pitfalls: Using an Object as a Map 266
Cheat Sheet: Working with Objects 270

18. Arrays
Overview 273
Creating Arrays 274
Array Indices 276
length 279
Holes in Arrays 282
Array Constructor Method 285
Array Prototype Methods 286
Adding and Removing Elements (Destructive) 286
Sorting and Reversing Elements (Destructive) 287
Concatenating, Slicing, Joining (Nondestructive) 289
Searching for Values (Nondestructive) 290
Iteration (Nondestructive) 291
Pitfall: Array-Like Objects 295
Best Practices: Iterating over Arrays 295

19. Regular Expressions
Regular Expression Syntax 297
Unicode and Regular Expressions 302
Creating a Regular Expression 302
RegExp.prototype.test: Is There a Match? 304
String.prototype.search: At What Index Is There a Match? 305
RegExp.prototype.exec: Capture Groups 305
String.prototype.match: Capture Groups or Return All Matching Substrings 307
String.prototype.replace: Search and Replace 307
Problems with the Flag /g 309
Tips and Tricks 311
Regular Expression Cheat Sheet 314

20. Dates
The Date Constructor 317
Table of Contents | viiDate Constructor Methods 318
Date Prototype Methods 319
Date Time Formats 322
Time Values: Dates as Milliseconds Since 1970-01-01 324

21. Math
Math Properties 327
Numerical Functions 328
Trigonometric Functions 329
Other Functions 330

22. JSON
Background 333
JSON.stringify(value, replacer?, space?) 337
JSON.parse(text, reviver?) 340
Transforming Data via Node Visitors 341

23. Standard Global Variables
Constructors 345
Error Constructors 345
Nonconstructor Functions 346
Dynamically Evaluating JavaScript Code via eval() and new Function() 347
The Console API 351
Namespaces and Special Values 356

24. Unicode and JavaScript
Unicode History 357
Important Unicode Concepts 357
Code Points 359
Unicode Encodings 359
JavaScript Source Code and Unicode 361
JavaScript Strings and Unicode 364
JavaScript Regular Expressions and Unicode 365

25. New in ECMAScript 5
New Features 369
Syntactic Changes 370
New Functionality in the Standard Library 370
Tips for Working with Legacy Browsers 372
Part IV. Tips, Tools, and Libraries

26. A Meta Code Style Guide
Table of ContentsExisting Style Guides 375
General Tips 375
Commonly Accepted Best Practices 377
Controversial Rules 382
Conclusion 386

27. Language Mechanisms for Debugging
28. Subclassing Built-ins
Terminology 389
Obstacle 1: Instances with Internal Properties 389
Obstacle 2: A Constructor That Can’t Be Called as a Function 392
Another Solution: Delegation 393

29. JSDoc: Generating API Documentation
The Basics of JSDoc 396
Basic Tags 397
Documenting Functions and Methods 399
Inline Type Information (“Inline Doc Comments”) 399
Documenting Variables, Parameters, and Instance Properties 400
Documenting Classes 401
Other Useful Tags 403

30. Libraries
Shims Versus Polyfills 405
Four Language Libraries 406
The ECMAScript Internationalization API 406
Directories for JavaScript Resources 408

31. Module Systems and Package Managers
Module Systems 411
Package Managers 412
Quick and Dirty Modules 412

32. More Tools
33. What to Do Next

Be the first to comment

Leave a Reply

Your email address will not be published.

*