JavaScript Enlightenment [Lindley 2013-01-10].pdf
(
1568 KB
)
Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
JavaScript Enlightenment
Cody Lindley
First Edition, based on JavaScript 1.5, ECMA-262, Edition 3
Table of Contents
About the Author
..................................................................................................................................
8
About the Technical Editors
..................................................................................................................
9
Michael Richardson
................................................................................................................................
9
Kyle Simpson
.........................................................................................................................................
9
Nathan Smith
........................................................................................................................................
9
Ben Nadel
..............................................................................................................................................
9
Ryan Florence
........................................................................................................................................
10
Nathan Logan
........................................................................................................................................
10
Introduction
.........................................................................................................................................
11
Why did I write this book?
......................................................................................................................
11
Who should read this book?
....................................................................................................................
12
Why JavaScript 1.5 & ECMA-262 Edition 3?
..............................................................................................
12
Why didn't I cover the Date(), Error(), RegEx() objects?
...........................................................................
12
Preface
.................................................................................................................................................
13
More code, less words
............................................................................................................................
13
Exhaustive code and repetition
...............................................................................................................
13
Color-coding Conventions
.......................................................................................................................
13
jsFiddle, JS Bin, and Firebug lite-dev
.......................................................................................................
14
Chapter 1 - JavaScript Objects
.............................................................................................................
15
Creating objects
.....................................................................................................................................
15
JavaScript constructors construct and return object instances
...................................................................
20
The JavaScript native/built-in object constructors
.....................................................................................
21
User-defined/non-native object constructor functions
................................................................................
23
2
Instantiating constructors using the new operator
....................................................................................
24
Creating shorthand/literal values from constructors
..................................................................................
25
Primitive (aka simple) values
..................................................................................................................
27
The primitive values null, undefined, "string", 10, true, and false are not objects
........................................
28
How primitive values are stored/copied in JavaScript
................................................................................
29
Primitive values are equal by value
..........................................................................................................
30
The string, number, and boolean primitive values act like objects when used like objects
............................
31
Complex (aka composite) values
.............................................................................................................
32
How complex values are stored/copied in JavaScript
.................................................................................
33
Complex objects are equal by reference
..................................................................................................
34
Complex objects have dynamic properties
................................................................................................
35
The typeof operator used on primitive and complex values
.......................................................................
35
Dynamic Properties allow for mutable objects
..........................................................................................
36
All constructor instances have constructor properties that point to their constructor function
.......................
37
Verify that an object is an instance of a particular constructor function
......................................................
39
An instance created from a constructor can have its own independent properties (aka instance properties) 40
..
The semantics between "JavaScript objects" vs. "Object() objects"
............................................................
42
Chapter 2 - Working with Objects and Properties
...............................................................................
43
Complex objects can contain most of the JavaScript values as properties
...................................................
43
Encapsulating complex objects in a programmatically beneficial way
.........................................................
44
Getting/setting/updating an object's properties using dot notation or bracket notation
................................
45
Deleting object properties
.......................................................................................................................
48
How references to object properties are resolved
.....................................................................................
48
Using hasOwnProperty, verify that an object property is not from the prototype chain
.................................
51
Checking if an object contains a given property using the in operator
........................................................
51
Enumerate (loop over) an object’s properties using the for in loop
.............................................................
52
Host objects vs. native objects
................................................................................................................
53
Enhancing & extending objects with Underscore.js
...................................................................................
54
Chapter 3 - Object()
.............................................................................................................................
57
Conceptual overview of using Object() objects
.........................................................................................
57
3
Object() parameters
...............................................................................................................................
58
Object() properties and methods
.............................................................................................................
58
Object() object instance properties and methods
.....................................................................................
59
Creating Object() objects using "object literals"
........................................................................................
59
All objects inherit from Object.prototype
.................................................................................................
61
Chapter 4 - Function()
.........................................................................................................................
63
Conceptual overview of using Function() objects
......................................................................................
63
Function() parameters
............................................................................................................................
63
Function() properties and methods
..........................................................................................................
64
Function object instance properties and methods
.....................................................................................
65
Functions always return a value
..............................................................................................................
65
Functions are first-class citizens (not just syntax, but values)
....................................................................
66
Passing parameters to a function
.............................................................................................................
67
this & arguments values available to all functions
.....................................................................................
67
The arguments.callee property
...............................................................................................................
68
The function instance length property & arguments.length
.......................................................................
69
Redefining function parameters
...............................................................................................................
70
Return a function before it is done (i.e. cancel function execution)
............................................................
70
Defining a function (statement, expression, or constructor)
.......................................................................
71
Invoking a function (function, method, constructor, or call() & apply())
......................................................
72
Anonymous functions
.............................................................................................................................
73
Self-invoking function expression
.............................................................................................................
73
Self-invoking anonymous function statements
..........................................................................................
74
Functions can be nested
.........................................................................................................................
74
Passing functions to functions & returning functions from functions
...........................................................
75
Invoking function statements before they are defined (aka function hoisting)
.............................................
76
A function can call itself (aka recursion)
...................................................................................................
77
Chapter 5 - The Head/Global Object
...................................................................................................
78
Conceptual overview of the head object
...................................................................................................
78
Global functions contained within the head object
....................................................................................
79
4
The head object vs. global properties and global variables
........................................................................
79
Referring to the head object
...................................................................................................................
80
The head object is implied and typically not referenced explicitly
..............................................................
81
Chapter 6 - The this Keyword
...............................................................................................................
83
Conceptual overview of this and how it refers to objects
...........................................................................
83
How is the value of this determined?
.......................................................................................................
84
The this keyword refers to the head object in nested functions
..................................................................
85
Working around the nested function issue by leveraging the scope chain
...................................................
87
Controlling the value of this using call() or apply()
....................................................................................
87
Using the this keyword inside a user-defined constructor function
..............................................................
88
The keyword this inside a prototype method refers to a constructor instance
.............................................
90
Chapter 7 - Scope & Closures
...............................................................................................................
92
Conceptual overview of JavaScript scope
.................................................................................................
92
JavaScript does not have block scope
......................................................................................................
93
Use var inside of functions to declare variables and avoid scope gotchas
....................................................
93
The scope chain (aka lexical scoping)
......................................................................................................
94
The scope chain lookup returns the first found value
................................................................................
96
Scope is determined during function definition, not invocation
...................................................................
96
Closures are caused by the scope chain
...................................................................................................
97
Chapter 8 - Function Prototype Property
.............................................................................................
99
Conceptual overview of the prototype chain
.............................................................................................
99
Why care about the prototype property?
..................................................................................................
100
Prototype is standard on all Function() instances
......................................................................................
101
The default prototype property is an Object() object
.................................................................................
101
Instances created from a constructor function are linked to the constructor’s prototype property
................
102
Last stop in the prototype chain is Object.prototype
.................................................................................
103
The prototype chain returns the first property match it finds in the chain
...................................................
104
Replacing the prototype property with a new object removes the default constructor property
....................
105
Instances that inherit properties from prototype will always get the latest values
........................................
106
5
Plik z chomika:
musli_com
Inne pliki z tego folderu:
JavaScript_ The Missing Manual [McFarland 2008-07-01].pdf
(21906 KB)
Professional jQuery [Otero 2012-05-01].pdf
(24031 KB)
Smashing Node.js_ JavaScript Everywhere [Rauch 2012-09-04].pdf
(16688 KB)
Practical Dojo Projects [Zammetti 2008-09-24].pdf
(7145 KB)
Beginning JavaScript (5th ed.) [McPeak & Wilton 2015-03-09].pdf
(37093 KB)
Inne foldery tego chomika:
3D Design - Programming
ActionScript
Actionscript - Flash - Flex - Air
Ada
ADO
Zgłoś jeśli
naruszono regulamin