E-Book, Englisch, 495 Seiten
McNavage JavaScript for Absolute Beginners
1. ed
ISBN: 978-1-4302-7218-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 495 Seiten
ISBN: 978-1-4302-7218-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
If you are new to both JavaScript and programming, this hands-on book is for you. Rather than staring blankly at gobbledygook, you'll explore JavaScript by entering and running hundreds of code samples in Firebug, a free JavaScript debugger. Then in the last two chapters, you'll leave the safety of Firebug and hand-code an uber cool JavaScript application in your preferred text editor. Written in a friendly, engaging narrative style, this innovative JavaScript tutorial covers the following essentials: Core JavaScript syntax, such as value types, operators, expressions, and statements provided by ECMAScript. Features for manipulating XHTML, CSS, and events provided by DOM. Object-oriented JavaScript, including prototypal and classical inheritance, deep copy, and mixins. Closure, lazy loading, advance conditional loading, chaining, currying, memoization, modules, callbacks, recursion, and other powerful function techniques. Encoding data with JSON or XML. Remote scripting with JSON-P or XMLHttpRequest Drag-and-drop, animated scrollers, skin swappers, and other cool behaviors. Optimizations to ensure your scripts run snappy. Formatting and naming conventions to prevent you from looking like a greenhorn. New ECMAScript 5, DOM 3, and HTML 5 features such as Object.create(), Function.prototype.bind(), strict mode, querySelector(), querySelectorAll(), and getElementsByClassName(). As you can see, due to its fresh approach, this book is by no means watered down. Therefore, over the course of your journey, you will go from JavaScript beginner to wizard, acquiring the skills recruiters desire.
Terry McNavage has been programming with JavaScript for 14 years and is the author of 'JavaScript for Absolute Beginners' (Apress, December 2010). In addition, Terry is an elite runner, typically running 100 or more miles per week, and a bit of a food geek. Like Brendan Eich, JavaScript's creator, Terry is from Pittsburgh, Pennsylvania. So he's hoping the Pirates raise the Jolly Roger more often than not in 2012 rather than notch their 20th losing season in a row.
Autoren/Hrsg.
Weitere Infos & Material
1;Cover;1
2;Title Page;2
3;Copyright Page;3
4;Dedication Page;4
5;Table of Contents;6
6;About the Author;14
7;About the Technical Reviewers;15
8;Acknowledgments;16
9;Preface;17
9.1;Opening Firebug;19
9.2;Enabling Firebug;20
9.3;Command Line;20
9.4;Command Editor;21
10;CHAPTER 1 Representing Data with Values;25
10.1;What Are Value Types?;25
10.2;Creating a String Literal;26
10.2.1;Commenting Code;26
10.2.2;Gluing Strings Together with the + Operator;27
10.3;Creating a Number Literal;28
10.4;Creating a Boolean Literal;29
10.5;Naming a Value with an Identifier;30
10.5.1;Can I Name a Variable Anything I Want?;30
10.5.2;Some Valid Identifiers Are Already Taken;31
10.6;Creating an Object Literal;33
10.6.1;Naming Members with Identifiers;37
10.7;Creating an Array Literal;38
10.8;Creating a Function Literal;43
10.9;Summary;47
11;CHAPTER 2 Type Conversion;48
11.1;String Members;48
11.1.1;Determining the Number of Characters;53
11.1.2;Decoding or Encoding Characters;55
11.1.3;Converting Case;56
11.1.4;Locating a Substring;58
11.1.5;Clipping a Substring;59
11.1.6;Replacing a Substring;60
11.1.7;Splitting a String into an Array of Smaller Strings;62
11.1.8;Searching with Regular Expressions;66
11.2;Explicitly Creating Wrappers;66
11.3;Converting a Value to Another Type;67
11.3.1;Converting a Value to a Number;69
11.3.2;Converting a Value to a String;73
11.4;Methods for Converting a Number to a String;74
11.4.1;Putting Off Learning RegExp Syntax;76
11.5;Summary;79
12;CHAPTER 3 Operators;80
12.1;Introducing Operator Precedence and Associativity;80
12.2;Using JavaScript Operators;83
12.2.1;Combining Math and Assignment Operations;84
12.2.2;Incrementing or Decrementing Values;89
12.2.3;Testing for Equality;91
12.2.4;Testing for Inequality;94
12.2.5;Comparing Objects, Arrays, and Functions;95
12.2.6;Determining Whether One Number or String Is Greater Than;98
12.2.7;Determining Whether One Number or String Is Less Than Another;100
12.2.8;Greater Than or Equal to, Less Than or Equal to;102
12.2.9;Creating More Complex Comparisons;104
12.2.10;Saying or With ||;106
12.2.11;Saying “and” with &&;107
12.2.12;Chaining || Expressions;108
12.2.13;Chaining && Expressions;110
12.2.14;Chaining || and && Expressions;112
12.2.15;Conditionally Returning One of Two Values;113
12.2.16;Making Two Expressions Count as One;116
12.2.17;Deleting a Member, Element, or Variable;117
12.3;Summary;118
13;CHAPTER 4 Controlling Flow;119
13.1;Writing an if Condition;120
13.1.1;Appending an else Clause;122
13.1.2;To Wrap or Not to Wrap;123
13.1.3;Coding Several Paths with the else if Idiom;124
13.1.4;Controlling Flow with Conditional Expressions;128
13.2;Taking One of Several Paths with a Switch;129
13.3;Writing a while Loop;138
13.3.1;Aborting an Iteration but Not the Loop;140
13.3.2;Replacing Break with Return in a Function;142
13.4;Writing a do while loop;144
13.5;Writing a for Loop;147
13.6;Enumerating Members with a for in Loop;149
13.7;Snappier Conditionals;151
13.8;Snappier Loops;158
13.9;Summary;166
14;CHAPTER 5 Member Inheritance;167
14.1;Creating Objects with a Constructor;167
14.2;Classical Inheritance;171
14.2.1;Determining Which Type or Types an Object Is an Instance Of;179
14.2.2;Inherited Members Are Shared Not Copied;180
14.2.3;Modifying New and Past Instances of a Type;182
14.2.4;Sharing a Prototype but Forgoing the Chain;185
14.2.5;Adding an Empty Chain Link;188
14.2.6;Stealing a Constructor;191
14.3;Prototypal Inheritance;193
14.4;Cloning Members;196
14.5;Mixins;198
14.6;Summary;201
15;CHAPTER 6 Functions and Arrays;202
15.1;Why Use Functions?;202
15.2;Functions Are Values;204
15.3;Function Members;205
15.4;Conditional Advance Loading;206
15.4.1;Writing Object.defineProperty();207
15.4.2;Writing Object.defineProperties();209
15.4.3;Writing Object.create();209
15.4.4;Using the new Functions;210
15.5;Lazy Loading;216
15.6;Recursion;219
15.7;Borrowing Methods with apply() or call();222
15.7.1;Overriding toString();222
15.7.2;Testing for an Array;225
15.7.3;Rewriting cloneMembers();227
15.8;Currying;229
15.9;Chaining Methods;234
15.10;Closure and Returning Functions;238
15.11;Passing a Configuration Object;244
15.12;Callback Functions;245
15.13;Memoization;247
15.14;Global Abatement with Modules;248
15.15;Arrays;251
15.15.1;Plucking Elements from an Array;251
15.15.2;Adding Elements to an Array;255
15.15.3;Gluing Two Arrays Together;257
15.15.4;Reversing the Elements in an Array;259
15.15.5;Sorting the Elements in an Array;260
15.15.6;Creating a String from an Array;265
15.15.7;Taking a Slice of an Array;266
15.15.8;Converting a Read-only Array-like Object to an Array;268
15.15.9;Inserting or Deleting Elements from an Array;271
15.16;Summary;275
16;CHAPTER 7 Traversing and Modifying the DOM Tree;276
16.1;DOM Tree;276
16.1.1;Is Every Node the Same?;277
16.1.2;Interfaces Are Sensibly Named;278
16.1.3;Querying the DOM Tree;278
16.1.4;Same Jargon as for a Family Tree;281
16.1.5;Traversing the DOM Tree;281
16.1.6;Descending with childNodes;281
16.1.7;Ascending with parentNode;283
16.1.8;Muddying the Waters with Whitespace;284
16.1.9;Coding Cascade Style;285
16.1.10;Moving Laterally;289
16.1.11;Converting a NodeList to an Array;292
16.1.12;Converting a NodeList to an Array for Internet Explorer;294
16.1.13;Traversing the DOM without childNodes;296
16.1.14;Finding an Element by ID;298
16.1.15;Finding Elements by Their Tag Names;299
16.1.16;Finding Elements by Class;300
16.1.17;Querying Attributes Like a Member;303
16.1.18;Querying Attributes with Methods;303
16.1.19;Querying Attr Nodes;306
16.1.20;Enumerating Attributes for an Element;307
16.1.21;Creating Element or Text Nodes;310
16.1.22;Deleting Content;313
16.1.23;Copying Content;314
16.1.24;Creating Elements with a Helper Function;315
16.1.25;Reordering Nested Lists;318
16.1.26;Where Did the Formatting Text Nodes Go?;323
16.2;Summary;326
17;CHAPTER 8 Scripting CSS;327
17.1;DOM Interfaces for Working with CSS;327
17.2;Clarifying Some CSS Jargon;328
17.2.1;How Does JavaScript Represent a Rule?;328
17.2.2;Two Other Declaration Blobs;330
17.3;Downloading the Sample Files;330
17.4;Querying a Style Attribute;333
17.5;Scripting Classes;338
17.6;Scripting Rules;340
17.7;Scripting Imported Style Sheets;346
17.8;Adding or Deleting a Rule;347
17.8.1;Adding a Rule to a Style Sheet;349
17.8.2;Deleting a Rule from a Style Sheet;352
17.9;Querying Overall Styles from the Cascade;354
17.10;Enabling and Disabling Style Sheets;358
17.11;Including or Importing Style Sheets;359
17.12;Embedding a Style Sheet;364
17.13;Summary;365
18;CHAPTER 9 Listening for Events;366
18.1;Working with the Event Object;366
18.2;Downloading Project Files;367
18.3;Advance Conditional Loading;371
18.4;Telling JavaScript to Stop Listening for an Event;372
18.5;Preventing Default Actions from Taking Place;373
18.6;Preventing an Event from Traversing the DOM Tree;374
18.7;Writing Helper Functions;376
18.7.1;Crawling the DOM Tree;376
18.7.2;Finding an Element by Class;377
18.7.3;Testing for getElementsByClassName();379
18.7.4;Querying the Cascade;381
18.8;Sliding Sprites;384
18.8.1;Preparing the Ground;384
18.8.2;Moving the Sprites;387
18.8.3;Snappier Sprites;390
18.9;Drag-and-Drop Behavior;395
18.9.1;Writing the Mousedown Event Listener;395
18.9.2;Writing the Mousemove Event Listener;399
18.9.3;Writing the Mouseup Event Listener;400
18.9.4;The doZ() Helper Function;402
18.9.5;Prepping the Drag;403
18.10;Swapping Skins by Key;411
18.11;Initiating Behaviors When the DOM Tree Is Available;415
18.12;Fighting Global Evil;415
18.13;Summary;416
19;CHAPTER 10 Scripting BOM;417
19.1;Downloading the Project Files;417
19.2;Remembering Visitor Data with Cookies;419
19.2.1;Getting the User’s Preference;419
19.2.2;Setting the User’s Skin Preference;421
19.2.3;Setting the User’s Preference;422
19.3;Animating with Timers;425
19.3.1;Preparing the Scrollers;425
19.3.2;Adding the Press Event Listener;428
19.3.3;Writing the Animation Function;430
19.3.4;Using the Gallery;432
19.3.4.1;Animating the Gallery;433
19.3.4.2;Swapping Sprites by ID or Class;438
19.4;Writing Dynamic Pages Using Ajax;441
19.4.1;Testing XMLHttpRequest from Your Local File System;442
19.4.2;Creating Tree Branches with createElem();442
19.4.3;Asynchronously Requesting Data;444
19.4.4;Parsing an HTML Response;446
19.4.5;Parsing an XML Response;450
19.4.6;Parsing Simple XML;455
19.4.7;Parsing JSON;459
19.4.8;JSON in a Nutshell;460
19.4.9;Padding JSON;465
19.5;Converting function declarations to expressions;469
19.6;Summary;478
19.7;Yielding with Timers;469
20;Index;479




