0%

Book Description

Pro JavaScript Development is a practical guide for front-end web developers who are experienced at building web pages with HTML, CSS, and JavaScript, and now wish to advance their JavaScript skills to a higher level. You will learn how to build large, well-structured, high quality, mobile-optimized web sites and apps, using the latest supported browser APIs, language features, and tools. This book teaches and shows you in practical hands-on terms how you can:

  • Master the performance, reliability, stability, and code manageability of your JavaScript
  • Understand and write efficient object-oriented and prototypal code, including full understanding of the this keyword
  • Boost the performance of your JavaScript code
  • Architect large web applications using common design patterns
  • Write high quality JavaScript code and avoid the pitfalls most likely to cause errors
  • Manage code dependencies with AMD and RequireJS
  • Develop for mobile, build games, and set up a real-time video chat using modern APIs such as Geolocation, Canvas and WebRTC
  • Document your code as the professionals do
  • Write command-line and web server applications in JavaScript with Node.js,
  • Use build tools, such as Grunt and Gulp, to automate repetitive tasks and improve your development workflow

Using real-world examples and applications that you'll build yourself, Pro JavaScript Development has unique, practical content that will make you a better JavaScript developer. Become a master of the latest JavaScript coding techniques and tools, and harness its best capabilities today.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewers
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Object-Oriented JavaScript
    1. Objects in JavaScript
      1. Custom Objects
      2. Classes
    2. Coding Conventions And Naming
      1. Rule 1: Use descriptive names
      2. Rule 2: Begin with a lowercase letter
      3. Rule 3: Use camel-case to represent word divisions
      4. Rule 4: Use all uppercase characters to represent universal constants
      5. Rule 5: Group together variable declarations in one statement at the top of every function block
    3. ECMAScript 5
      1. JSON Data Format Parsing
      2. Strict Mode
      3. Function binding
      4. Array Methods
      5. Object Methods
    4. Summary
  12. Chapter 2: Documenting JavaScript
    1. Inline and Block Comments
    2. Structured JavaScript Documentation
    3. The YUIDoc Documentation Format
      1. Documenting “Classes”, Constructors, Properties and Methods
      2. Documenting Events
      3. Documenting Code Examples
      4. Other YUIDoc Documentation Tags
    4. Expressive Documentation Formatting – Markdown
      1. Grouping Content Under Headings
      2. Breaking Lines And Creating Paragraphs
      3. Creating Lists
      4. Emphasizing Text
      5. Displaying Code
      6. Adding Quotes
      7. Linking To URLs
      8. Inserting Images
      9. Creating Horizontal Rules
      10. Using Backslash To Insert Reserved Characters
      11. For Everything Else, There’s HTML
    5. Creating a Documentation Website Using YUIDoc
      1. Taking It Further
    6. Summary
  13. Chapter 3: Writing High-Quality JavaScript
    1. Performing Static Code Analysis
      1. JSLint
      2. JSHint
      3. Google Closure Compiler and Linter
      4. Choosing a Static Code Analysis Tool
    2. Unit Testing In JavaScript
      1. Unit Testing Frameworks For JavaScript
      2. Using Jasmine For JavaScript Unit Testing
    3. Handling Runtime Errors
      1. JavaScript’s Native Error Types
      2. Wrap Code That May Error In A try-catch Statement
      3. Detecting The Type Of Error Thrown
      4. Creating Custom Error Types
    4. Measuring Code Quality
      1. Unit Test Code Coverage
      2. Measuring Code Complexity
    5. Summary
  14. Chapter 4: Boosting JavaScript Performance
    1. Improving Page Loading Time
      1. HTML Tag Order Matters
      2. GZip Encode Delivery Of Your JavaScript Files
      3. Minification, Obfuscation, and Compilation
      4. Lazy Loading JavaScript Files On Demand
    2. Optimize Document Object Manipulation
      1. Minimise Access to Page Elements
      2. Close Existing Elements Where Possible
      3. Utilise The Offline DOM
      4. Use CSS To Manipulate Page Styles Rather Than JavaScript
    3. Improving DOM Event Performance
      1. Delegate Events To Parent Elements
      2. Handle Rapid-Fire Events With Framing
    4. Improving Function Performance
      1. Storing Previous Function Return Values With Memoization
    5. Faster String Manipulation With Regular Expressions
    6. Faster Use Of Arrays
      1. Fast Array Creation
      2. Fast Array Looping
    7. Offload Intensive Tasks To Web Workers
      1. Using a Web Worker to Process Image Data
    8. Basic Performance Measurements
    9. Summary
  15. Chapter 5: Design Patterns: Creational
    1. What Are Design Patterns?
    2. Creational Design Patterns
      1. The Factory Pattern
      2. The Abstract Factory Pattern
      3. The Builder Pattern
      4. The Prototype Pattern
      5. The Singleton Pattern
    3. Summary
  16. Chapter 6: Design Patterns: Structural
    1. The Adapter Pattern
    2. The Composite Pattern
    3. The Decorator Pattern
    4. The Façade Pattern
    5. The Flyweight Pattern
    6. The Mixin Pattern
    7. The Module Pattern
    8. The Proxy Pattern
    9. Summary
  17. Chapter 7: Design Patterns: Behavioral
    1. The Chain of Responsibility Pattern
    2. The Command Pattern
    3. The Iterator Pattern
    4. The Observer Pattern
    5. The Mediator Pattern
    6. The Memento Pattern
    7. The Promises Pattern
    8. The Strategy Pattern
    9. Summary
  18. Chapter 8: Design Patterns: Architectural
    1. The Model-View-Controller (MVC) Pattern
    2. The Model-View-Presenter (MVP) Pattern
    3. The Model-View-ViewModel (MVVM) Pattern
    4. Architectural Pattern Frameworks
    5. Summary
  19. Chapter 9: Managing Code File Dependencies
    1. Using RequireJS to Manage Code File Dependencies
    2. Loading and Initializing RequireJS
    3. Using Aliases For Module Names
    4. Content Delivery Networks and Fallbacks
    5. Creating Modules
    6. Loading Additional Scripts On Demand
    7. The RequireJS Code Optimizer Tool
    8. Additional Plugins for RequireJS
    9. Alternatives To RequireJS
    10. Summary
  20. Chapter 10: Mobile JavaScript Development
    1. The Constraints of Mobile Web Development
      1. Battery Life
      2. Network Bandwidth Speeds And Latency
      3. On-Board Memory Size
      4. Operating System Responsiveness
    2. Accessing Mobile Device Sensors with JavaScript
      1. Accessing The Geolocation Sensor
      2. Accessing The Touch Sensor
      3. Accessing The Orientation and Direction Sensors
      4. Accessing The Motion Sensor
      5. The Missing Sensors
      6. Event Framing For Sensor Data
      7. Taking Sensor Data Further
    3. Network Connection Failures And Offline States
      1. Detecting Online and Offline States
      2. Persisting Data With The Web Storage API
      3. The HTML5 Application Cache
    4. JavaScript For Responsive Design
    5. Summary
  21. Chapter 11: Building Games with Canvas API
    1. Basic Drawing Operations in Canvas
    2. High-Definition Canvas Elements
    3. Building Games Using Canvas
      1. Drawing Images onto a Canvas
      2. Animation in Canvas
      3. Game Control
      4. Collision Detection
      5. The Game Loop
      6. Layering Canvases for Better Performance
    4. Building a “Frogger” Game in Canvas
    5. Summary
  22. Chapter 12: Using WebRTC for Video Chat
    1. The WebRTC Specification
    2. Accessing the Webcam and Microphone
    3. Creating a Simple Video Chat Web Application
      1. Connection and Signalling
    4. Building the Video Chat Client
    5. Summary
  23. Chapter 13: Using Client-Side Templates
    1. Dynamically Updating Page Content
    2. Loading HTML Dynamically Via Ajax
    3. Client-Side Templating
      1. Client-Side Templating without a Library
      2. Client-Side Templating with Mustache.js
      3. Client-Side Templating with Handlebars.js
      4. Alternative Client-Side Templating Libraries
    4. Consider Progressive Enhancement
    5. Summary
  24. Chapter 14: The Node.js Application Platform
    1. Installing Node.js
    2. Writing Node.js Applications
      1. The Console
      2. Loading Modules
    3. Node.js Packages
    4. Splitting a Node.js Application across Multiple Files
    5. Node.js Frameworks for Web Applications
      1. Express
      2. Socket.IO
    6. Node.js Hosting
    7. Summary
  25. Chapter 15: Build Tools and Automation
    1. Build Tools
      1. Grunt—The JavaScript Task Runner
      2. Gulp.js—The Streaming Build System
      3. Using Build Tools to Automate Common Tasks
    2. Managing Third-Party Libraries and Frameworks
    3. Project Setup and Scaffolding
    4. Summary
  26. Chapter 16: Browser Developer Tools
    1. Locating the Hidden Browser Developer Tools
    2. The JavaScript Console
      1. Outputting Messages to the Console Window
      2. Using the Console for Performance Measurement
      3. Remove Code References to the Console Object for Release
    3. Debugging Running JavaScript Code
      1. Working with Minified Code
      2. Pause and Observe Running JavaScript Code
    4. Profiling JavaScript Code
      1. Locating Memory Leaks
      2. Identifying Performance Bottlenecks
    5. Summary
  27. Index
18.191.102.112