| |
| |
preface | |
| |
| |
acknowledgments | |
| |
| |
about this book | |
| |
| |
about the authors | |
| |
| |
| |
Preparing for Training | |
| |
| |
| |
Enter the ninja | |
| |
| |
| |
The JavaScript libraries we'll be tapping | |
| |
| |
| |
Understanding the JavaScript language | |
| |
| |
| |
Cross-browser considerations | |
| |
| |
| |
Current best practices | |
| |
| |
Current best practice: testing | |
| |
| |
Current best practice: performance analysis | |
| |
| |
| |
Summary | |
| |
| |
| |
Arming with testing and debugging | |
| |
| |
| |
Debugging code | |
| |
| |
Logging | |
| |
| |
Breakpoints | |
| |
| |
| |
Test generation | |
| |
| |
| |
Testing frameworks | |
| |
| |
QUnit | |
| |
| |
YUI Test | |
| |
| |
JsUnit | |
| |
| |
Newer unit-testing frameworks | |
| |
| |
| |
The fundamentals of a test suite | |
| |
| |
The assertion | |
| |
| |
Test groups | |
| |
| |
Asynchronous testing | |
| |
| |
| |
Summary | |
| |
| |
| |
Apprentice Training | |
| |
| |
| |
Functions are fundamental | |
| |
| |
| |
What's with the functional difference? | |
| |
| |
Why is JavaScript's functional nature important? | |
| |
| |
Sorting with a comparator | |
| |
| |
| |
Declarations | |
| |
| |
Scoping and functions | |
| |
| |
| |
Invocations | |
| |
| |
From arguments to function parameters | |
| |
| |
Invocation as a function | |
| |
| |
Invocation as a method | |
| |
| |
Invocation as a constructor | |
| |
| |
Invocation with the apply() and call() methods | |
| |
| |
| |
Summary | |
| |
| |
| |
Wielding functions | |
| |
| |
| |
Anonymous functions | |
| |
| |
| |
Recursion | |
| |
| |
Recursion in named functions | |
| |
| |
Recursion with methods | |
| |
| |
The pilfered reference problem | |
| |
| |
Inline named functions | |
| |
| |
The callee property | |
| |
| |
| |
Fun with function as objects | |
| |
| |
Storing functions | |
| |
| |
Self-memoizing functions | |
| |
| |
Faking array methods | |
| |
| |
| |
Variable-length argument lists | |
| |
| |
Using apply() to supply variable arguments | |
| |
| |
Function overloading | |
| |
| |
| |
Checking for functions | |
| |
| |
| |
Summary | |
| |
| |
| |
Closing in on closures | |
| |
| |
| |
How closures work | |
| |
| |
| |
Putting closures to work | |
| |
| |
Private variables | |
| |
| |
Callbacks and timers | |
| |
| |
| |
Binding function contexts | |
| |
| |
| |
Partially applying functions | |
| |
| |
| |
Overriding function behavior | |
| |
| |
Memoization | |
| |
| |
Function wrapping | |
| |
| |
| |
Immediate functions | |
| |
| |
Temporary scope and private variables | |
| |
| |
Loops | |
| |
| |
Library wrapping | |
| |
| |
| |
Summary | |
| |
| |
| |
Object-orientation with prototypes | |
| |
| |
| |
Instantiation and prototypes | |
| |
| |
Object instantiation | |
| |
| |
Object typing via constructors | |
| |
| |
Inheritance and the prototype chain | |
| |
| |
HTML DOM prototypes | |
| |
| |
| |
The gotchas! | |
| |
| |
Extending Object | |
| |
| |
Extending Number | |
| |
| |
Subclassing native objects | |
| |
| |
Instantiation issues | |
| |
| |
| |
Writing class-like code | |
| |
| |
Checking for function serializability | |
| |
| |
Initialization of subclasses | |
| |
| |
Preserving super-methods | |
| |
| |
| |
Summary | |
| |
| |
| |
Wrangling regular expressions | |
| |
| |
| |
Why regular expressions rock | |
| |
| |
| |
A regular expression refresher | |
| |
| |
Regular expressions explained | |
| |
| |
Terms and operators | |
| |
| |
| |
Compiling regular expressions | |
| |
| |
| |
Capturing matching segments | |
| |
| |
Performing simple captures | |
| |
| |
Matching using global expressions | |
| |
| |
Referencing captures | |
| |
| |
Non-capturing groups | |
| |
| |
| |
Replacing using functions | |
| |
| |
| |
Solving common problems with regular expressions | |
| |
| |
Trimming a string | |
| |
| |
Matching newlines | |
| |
| |
Unicode | |
| |
| |
Escaped characters | |
| |
| |
| |
Summary | |
| |
| |
| |
Taming threads and timers | |
| |
| |
| |
How timers and threading work | |
| |
| |
Setting and clearing timers | |
| |
| |
Timer execution within the execution thread | |
| |
| |
Differences between timeouts and intervals | |
| |
| |
| |
Minimum timer delay and reliability | |
| |
| |
| |
Dealing with computationally expensive processing | |
| |
| |
| |
Central timer control | |
| |
| |
| |
Asynchronous testing | |
| |
| |
| |
Summary | |
| |
| |
| |
Ninja Training | |
| |
| |
| |
Ninja alchemy: runtime code evaluation | |
| |
| |
| |
Code evaluation mechanisms | |
| |
| |
Evaluation with the eval() method | |
| |
| |
Evaluation via the Function constructor | |
| |
| |
Evaluation with timers | |
| |
| |
Evaluation in the global scope | |
| |
| |
Safe code evaluation | |
| |
| |
| |
Function "decompilation" | |
| |
| |
| |
Code evaluation in action | |
| |
| |
Converting JSON | |
| |
| |
Importing namespaced code | |
| |
| |
JavaScript compression and obfuscation | |
| |
| |
Dynamic code rewriting | |
| |
| |
Aspect-oriented script tags | |
| |
| |
Metalanguages and DSLs | |
| |
| |
| |
Summary | |
| |
| |
| |
With statements | |
| |
| |
| |
What's with "with"? | |
| |
| |
Referencing properties within a with scope | |
| |
| |
Assignments within a with scope | |
| |
| |
Performance considerations | |
| |
| |
| |
Real-world examples | |
| |
| |
| |
Importing namespaced code | |
| |
| |
| |
Testing | |
| |
| |
| |
Templating with "with" | |
| |
| |
| |
Summary | |
| |
| |
| |
Developing cross-browser strategies | |
| |
| |
| |
Choosing which browsers to support | |
| |
| |
| |
The five major development concerns | |
| |
| |
Browser bugs and differences | |
| |
| |
Browser bug fixes | |
| |
| |
Living with external code and markup | |
| |
| |
Missing features | |
| |
| |
Regressions | |
| |
| |
| |
Implementation strategies | |
| |
| |
Safe cross-browser fixes | |
| |
| |
Object detection | |
| |
| |
Feature simulation | |
| |
| |
Untestable browser issues | |
| |
| |
| |
Reducing assumptions | |
| |
| |
| |
Summary | |
| |
| |
| |
Cutting through attributes, properties, and CSS | |
| |
| |
| |
DOM attributes and properties | |
| |
| |
Cross-browser naming | |
| |
| |
Naming restrictions | |
| |
| |
Differences between XML and HTML | |
| |
| |
Behavior of custom attributes | |
| |
| |
Performance considerations | |
| |
| |
| |
Cross-browser attribute issues | |
| |
| |
DOM id/name expansion | |
| |
| |
URL normalization | |
| |
| |
The style attribute | |
| |
| |
The type attribute | |
| |
| |
The tab index problem | |
| |
| |
Node names | |
| |
| |
| |
Styling attribute headaches | |
| |
| |
Where are my styles? | |
| |
| |
Style property naming | |
| |
| |
The float style property | |
| |
| |
Conversion of pixel values | |
| |
| |
Measuring heights and widths | |
| |
| |
Seeing through opacity | |
| |
| |
Riding the color wheel | |
| |
| |
| |
Fetching computed styles | |
| |
| |
| |
Summary | |
| |
| |
| |
Master Training | |
| |
| |
| |
Surviving events | |
| |
| |
| |
Binding and unbinding event handlers | |
| |
| |
| |
The Event object | |
| |
| |
| |
Handler management | |
| |
| |
Centrally storing associated information | |
| |
| |
Managing event handlers | |
| |
| |
| |
Triggering events | |
| |
| |
Custom events | |
| |
| |
| |
Bubbling and delegation | |
| |
| |
Delegating events to an ancestor | |
| |
| |
Working around browser deficiencies | |
| |
| |
| |
The document ready event | |
| |
| |
| |
Summary | |
| |
| |
| |
Manipulating the DOM | |
| |
| |
| |
Injecting HTML into the DOM | |
| |
| |
Converting HTML to DOM | |
| |
| |
Inserting into the document | |
| |
| |
Script execution | |
| |
| |
| |
Cloning elements | |
| |
| |
| |
Removing elements | |
| |
| |
| |
Text contents | |
| |
| |
Setting text | |
| |
| |
Getting text | |
| |
| |
| |
Summary | |
| |
| |
| |
CSS selector engines | |
| |
| |
| |
The W3C Selectors API | |
| |
| |
| |
Using XPath to find elements | |
| |
| |
| |
The pure-DOM implementation | |
| |
| |
Parsing the selector | |
| |
| |
Finding the elements | |
| |
| |
Filtering the set | |
| |
| |
Recursing and merging | |
| |
| |
Bottom-up selector engine | |
| |
| |
| |
Summary | |
| |
| |
index | |