O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning from jQuery

Book Description

If you’re comfortable with jQuery but a bit shaky with JavaScript, this concise guide will help you expand your knowledge of the language—especially the code that jQuery covers up for you. Many jQuery devotees write as little code as possible, but with some JavaScript under your belt, you can prevent errors, reduce overhead, and make your application code more efficient.

This book explores event handling, prototypes, and working with the DOM and AJAX through examples and lots of code. You’ll learn common conventions and patterns in JavaScript and—if you’ve never coded with JavaScript before—a tutorial will take you through the basics.

  • Enhance your jQuery code by using object constructors and prototypes
  • Reduce overhead and gain more control by handling events with JavaScript
  • Work with the DOM much faster with JavaScript than you can with jQuery
  • Send a few AJAX requests without having to load the entire jQuery library
  • Understand the importance of JavaScript code standards, comments, code reuse, and anti-patterns
  • Enlist JavaScript resources, such as a good IDE, a syntax checker, and version control

Table of Contents

  1. Preface
    1. Who This Book Is For
    2. Who This Book Isn’t For
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  2. 1. Event Handling
    1. Listening for Events
      1. Events in jQuery
      2. Events in JavaScript
      3. Events in Internet Explorer 8
      4. Writing a Wrapper Function
      5. Adding Event Handlers to Multiple Elements
    2. Event Propagation
      1. Internet Explorer’s .attachEvent
    3. Triggering Events
      1. Triggering Events in Internet Explorer 8
      2. Writing a Wrapper Function to Trigger Events
    4. Removing Event Handlers
      1. Removing Event Handlers in Internet Explorer 8
      2. Writing a Wrapper Function to Remove Events
    5. Adding a “Once Only” Event Listener
    6. Summary
  3. 2. Constructors and Prototypes
    1. Constructors
      1. Method Chaining
      2. Constructor, Not Function
    2. Prototypes
      1. .hasOwnProperty
      2. Editing the Prototype of Existing Objects
    3. Summary
  4. 3. DOM Traversal and Manipulation
    1. Selecting an Element
      1. Selecting Elements with a CSS Selector
    2. Selecting Children
    3. Selecting the Next Element
    4. Creating an Element
    5. Modifying an Existing Element
    6. Cycling Through Elements
    7. Moving and Copying Elements
    8. Summary
  5. 4. AJAX
    1. Sending an AJAX Request
    2. Debugging
      1. Debugging Sent AJAX Requests
    3. Sending POST Requests in JavaScript
    4. Writing a Wrapper Function
    5. A Simple Application of AJAX
    6. Designing a Site with AJAX
    7. Summary
  6. 5. JavaScript Conventions
    1. Writing JavaScript
      1. Comments
      2. Coding Standards
        1. Whitespace
        2. Curly braces
        3. Naming conventions
    2. Literals Notation
      1. Object Literals
      2. Other Literals
    3. Optimizations
      1. Algorithms
      2. Caching Variables
      3. parseInt
      4. Loops
      5. Minimize Repeated Expressions
    4. Functions
      1. Declarations Versus Expressions
      2. Function Callbacks
      3. If Invoking Self-Defining Functions
    5. Code Reuse
    6. Common Antipatterns
      1. Using eval
      2. with
      3. document.write
    7. Common Design Patterns
      1. The Singleton Pattern
      2. The Factory Pattern
      3. The Iterator Pattern
      4. The Facade Pattern
    8. Summary
  7. A. JavaScript Basics
    1. Hello World!
    2. Comments
    3. Variables
    4. Numbers
      1. The Assignment Operators
    5. Functions
      1. Hoisting Example
      2. Functions as Arguments
      3. Returning a Value
    6. Objects
    7. Finding the Type of a Variable
    8. Arrays
      1. Detecting an Array
    9. Looping
      1. The for Loop
      2. The while Loop
      3. The do-while Loop
      4. The break and continue Statements
      5. for..in statements
    10. Conditional Statements
      1. The if Statement
      2. Comparison Operators
      3. Logical Operators
        1. Falsy values
      4. The switch Statement
    11. Delays
    12. Regular Expressions
      1. Regular Expressions in String Functions
    13. Error Handling
    14. Summary
  8. B. JavaScript Resources
    1. A Good IDE
    2. GitHub
    3. JSHint
    4. JSPerf
    5. Mozilla Developer Network
    6. Pastebins
      1. Gist
      2. JSFiddle
    7. Version Control Software
  9. About the Author
  10. Colophon
  11. Copyright