Secrets of the JavaScript Ninja
John Resig and Bear Bibeault
  • December 2012
  • ISBN 9781933988696
  • 392 pages
  • printed in black & white

From two masters, the art of crafting effective cross-browser JavaScript.

Glenn Stokol, Oracle Corporation

Secrets of the Javascript Ninja takes you on a journey towards mastering modern JavaScript development in three phases: design, construction, and maintenance. Written for JavaScript developers with intermediate-level skills, this book will give you the knowledge you need to create a cross-browser JavaScript library from the ground up.

Secrets of the JavaScript Ninja, Second Edition is now available from Manning!

Table of Contents detailed table of contents


acknowledgments about this book about the authors





Part 1 Preparing for training

1. Chapter 1 Enter the ninja

1.1. The JavaScript libraries we’ll be tapping

1.2. Understanding the JavaScript language

1.3. Cross-browser considerations

1.4. Current best practices

1.5. Summary

2. Chapter 2 Arming with testing and debugging

2.1. Debugging code

2.2. Test generation

2.3. Testing frameworks

2.4. The fundamentals of a test suite

2.5. Summary

Part 2 Apprentice training

3. Chapter 3 Functions are fundamental

3.1. What’s with the functional difference?

3.2. Declarations

3.3. Invocations

3.4. Summary

4. Chapter 4 Wielding functions

4.1. Anonymous functions

4.2. Recursion

4.3. Fun with function as objects

4.4. Variable-length argument lists

4.5. Checking for functions

4.6. Summary

5. Chapter 5 Closing in on closures

5.1. How closures work

5.2. Putting closures to work

5.3. Binding function contexts

5.4. Partially applying functions

5.5. Overriding function behavior

5.6. Immediate functions

5.7. Summary

6. Chapter 6 Object-orientation with prototypes

6.1. Instantiation and prototypes

6.2. The gotchas!

6.3. Writing class-like code

6.4. Summary

7. Chapter 7 Wrangling regular expressions

7.1. Why regular expressions rock

7.2. A regular expression refresher

7.3. Compiling regular expressions

7.4. Capturing matching segments

7.5. Replacing using functions

7.6. Solving common problems with regular expressions

7.7. Summary

8. Chapter 8 Taming threads and timers

8.1. How timers and threading work

8.2. Minimum timer delay and reliability

8.3. Dealing with computationally expensive processing

8.4. Central timer control

8.5. Asynchronous testing

8.6. Summary

Part 3 Ninja training

9. Chapter 9 Ninja alchemy: runtime code evaluation

9.1. Code evaluation mechanisms

9.2. Function “decompilation”

9.3. Code evaluation in action

9.4. Summary

10. Chapter 10 With statements

10.1. What’s with “with”?

10.2. Real-world examples

10.3. Importing namespaced code

10.4. Testing

10.5. Templating with “with”

10.6. Summary

11. Chapter 11 Developing cross-browser strategies

11.1. Choosing which browsers to support

11.2. The five major development concerns

11.3. Implementation strategies

11.4. Reducing assumptions

11.5. Summary

12. Chapter 12 Cutting through attributes, properties, and CSS

12.1. DOM attributes and properties

12.2. Cross-browser attribute issues

12.3. Styling attribute headaches

12.4. Fetching computed styles

12.5. Summary

Part 4 Master training

13. Chapter 13 Surviving events

13.1. Binding and unbinding event handlers

13.2. The Event object

13.3. Handler management

13.4. Triggering events

13.5. Bubbling and delegation

13.6. The document ready event

13.7. Summary

14. Chapter 14 Manipulating the DOM

14.1. Injecting HTML into the DOM

14.2. Cloning elements

14.3. Removing elements

14.4. Text contents

14.5. Summary

15. Chapter 15 CSS selector engines

15.1. The W3C Selectors API

15.2. Using XPath to find elements

15.3. The pure-DOM implementation

15.4. Summary

© 2014 Manning Publications Co.

About the Technology

JavaScript developers commonly rely on collections of reusable JavaScript code--written by themselves or by someone else at their company. Alternatively, they rely on code from a third party. But in all these cases they need to know how to either construct a cross-browser library from scratch or be adept at using and maintaining their library of choice.

About the book

You can't always attack software head-on. Sometimes you come at it sideways or sneak up from behind. You need to master an arsenal of tools and know every stealthy trick. You have to be a ninja.

Secrets of the JavaScript Ninja leads you down the pathway to JavaScript enlightenment. This unique book starts with key concepts, like the relationships between functions, objects, and closures, taught from the master's perspective. You'll grow from apprentice to ninja as you soak up fresh insights on the techniques you use every day and discover features and capabilities you never knew about. When you reach the final chapters, you'll be ready to code brilliant JavaScript applications and maybe even write your own libraries and frameworks.

You don't have to be a ninja to read this book—just be willing to become one. Are you ready?

What's inside

  • Functions, objects, closures, regular expressions, and more
  • Seeing applications and libraries from the right perspective
  • Dealing with the complexities of cross-browser development
  • Modern JavaScript design

About the reader

Written to be accessible to JavaScript developers with intermediate-level skills, this book will give you the knowledge you need to create a cross-browser JavaScript library from the ground up.

About the authors

John Resig is an acknowledged JavaScript authority and the creator of the jQuery library. Bear Bibeault is a web developer and coauthor of Ajax in Practice, Prototype and Scriptaculous in Action, and jQuery in Action from Manning.

  • combo $39.99 pBook + eBook
  • eBook $31.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Consistent with the jQuery motto, "Write less, do more".

André Roberge, Université Saint-Anne

Interesting and original techniques.

Scott Sauyet, Four Winds Software

Read this book and you'll no longer blindly plug in a snippet of code and marvel at how it works - you'll understand "why" it works.

Joe Litton, Collaborative Software Developer,

Will help you raise your JavaScript to the realm of the masters.

Christopher Haupt,