Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 172 trang
THÔNG TIN TÀI LIỆU
Cấu trúc
Table of Contents
Preface
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Good Parts
Why JavaScript?
Analyzing JavaScript
A Simple Testing Ground
Grammar
Whitespace
Names
Numbers
Strings
Statements
Expressions
Literals
Functions
Objects
Object Literals
Retrieval
Update
Reference
Prototype
Reflection
Enumeration
Delete
Global Abatement
Functions
Function Objects
Function Literal
Invocation
The Method Invocation Pattern
The Function Invocation Pattern
The Constructor Invocation Pattern
The Apply Invocation Pattern
Arguments
Return
Exceptions
Augmenting Types
Recursion
Scope
Closure
Callbacks
Module
Cascade
Curry
Memoization
Inheritance
Pseudoclassical
Object Specifiers
Prototypal
Functional
Parts
Arrays
Array Literals
Length
Delete
Enumeration
Confusion
Methods
Dimensions
Regular Expressions
An Example
Construction
Elements
Regexp Choice
Regexp Sequence
Regexp Factor
Regexp Escape
Regexp Group
Regexp Class
Regexp Class Escape
Regexp Quantifier
Methods
Array
Function
Number
Object
RegExp
String
Style
Beautiful Features
Awful Parts
Global Variables
Scope
Semicolon Insertion
Reserved Words
Unicode
typeof
parseInt
+
Floating Point
NaN
Phony Arrays
Falsy Values
hasOwnProperty
Object
Bad Parts
==
with Statement
eval
continue Statement
switch Fall Through
Block-less Statements
++ --
Bitwise Operators
The function Statement Versus the function Expression
Typed Wrappers
new
void
JSLint
Undefined Variables and Functions
Members
Options
Semicolon
Line Breaking
Comma
Required Blocks
Forbidden Blocks
Expression Statements
for in Statement
switch Statement
var Statement
with Statement
=
== and !=
Labels
Unreachable Code
Confusing Pluses and Minuses
++ and --
Bitwise Operators
eval Is Evil
void
Regular Expressions
Constructors and new
Not Looked For
HTML
JSON
Report
Syntax Diagrams
JSON
JSON Syntax
Using JSON Securely
A JSON Parser
Index
Nội dung
[...]... clauses: the initialization, the condition, and the increment First, the initialization is done, which typically initializes the loop variable Then, the condition is evaluated Typically, this tests the loop variable against a completion criterion If the condition is omitted, then a condition of true is assumed If the condition is falsy, the loop breaks Otherwise, the block is executed, then the increment... languages contain good parts and bad parts I discovered that I could be a better programmer by using only the good parts and avoiding the bad parts After all, how can you build something good out of bad parts? It is rarely possible for standards committees to remove imperfections from a language because doing so would cause the breakage of all of the bad programs that depend on those bad parts They are usually... ternary operator followed by another expression, then by :, and then by yet another expression • An invocation • A refinement The ? ternary operator takes three operands If the first operand is truthy, it produces the value of the second operand But if the first operand is falsy, it produces the value of the third operand Expressions | 15 The operators at the top of the operator precedence list in... logical and && The || operator produces the value of its first operand if the first operand is truthy Otherwise, it produces the value of the second operand invocation ( ) expression , Invocation causes the execution of a function value The invocation operator is a pair of parentheses that follow the function value The parentheses can contain arguments that will be delivered to the function There will... because it is the language of the web browser Its association with the browser makes it one of the most popular programming languages in the world At the same time, it is one of the most despised programming languages in the world The API of the browser, the Document Object Model (DOM) is quite awful, and JavaScript is unfairly blamed The DOM would be painful to work with in any language The DOM is poorly... digit exponent e + E - digit If a number literal has an exponent part, then the value of the literal is computed by multiplying the part before the e by 10 raised to the power of the part after the e So 100 and 1e2 are the same number Negative numbers can be formed by using the – prefix operator The value NaN is a number value that is the result of an operation that cannot produce a normal result NaN is... gives us the tools to mitigate this problem In a few cases, we can’t ignore the bad parts There are some unavoidable awful parts, which will be called out as they occur They will also be summarized in Appendix A But we will succeed in avoiding most of the bad parts in this book, summarizing much of what was left out in Appendix B If you want to learn more about the bad parts and how to use them badly,... Shakespeare, The Tragedy of Titus Andronicus This chapter introduces the grammar of the good parts of JavaScript, presenting a quick overview of how the language is structured We will represent the grammar with railroad diagrams The rules for interpreting these diagrams are simple: • You start on the left edge and follow the tracks to the right edge • As you go, you will encounter literals in ovals, and... detail in the next chapter Literals Object literals are a convenient notation for specifying new objects The names of the properties can be specified as names or as strings The names are treated as literal names, not as variable names, so the names of the properties of the object must be known at compile time The values of the properties are expressions There will be more about object literals in the next... to prevent fall through into the next case The break statement can be used to exit from a switch while statement while ( expression ) block The while statement performs a simple loop If the expression is falsy, then the loop will break While the expression is truthy, the block will be executed The for statement is a more complicated looping statement It comes in two forms The conventional form is controlled . languages contain good parts and bad parts. I discovered that I
could be a better programmer by using only the good parts and avoiding the bad
parts. After. Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. JavaScript: The Good Parts, the image of