You are previewing Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language.
O'Reilly logo
Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language

Book Description

Create more robust applications with a test-first approach to JavaScript

Reliable JavaScript, How to Code Safely in the World's Most Dangerous Language demonstrates how to create test-driven development for large-scale JavaScript applications that will stand the test of time and stay accurate through long-term use and maintenance. Taking a test-first approach to software architecture, this book walks you through several patterns and practices and explains what they are supposed to do by having you write unit tests. Write the code to pass the unit tests, so you not only develop your technique for structuring large-scale applications, but you also learn how to test your work. You'll come away with hands-on practice that results in code that is correct from the start, and has the test coverage to ensure that it stays correct during subsequent maintenance. All code is provided both in the text and on the web, so you can immediately get started designing more complete, robust applications.

JavaScript has graduated from field-validation scripts to full-scale applications, but many developers still approach their work as if they were writing simple scripts. If you're one of those developers, this book is the solution you need to whip your code into shape and create JavaScript applications that work.

  • Write more concise and elegant code by thinking in JavaScript

  • Test the implementation and use of common design patterns

  • Master the use of advanced JavaScript features

  • Ensure your code's conformance to your organization's standards

  • If you're ready to step up your code and develop more complete software solutions, Reliable JavaScript is your essential resource.

    Table of Contents

    1. INTRODUCTION
      1. THE RISE OF JAVASCRIPT AS A FIRST-CLASS LANGUAGE
      2. THE EASE OF WRITING TRULY DISASTROUS CODE IN JAVASCRIPT
      3. THE EASE OF UNINTENTIONALLY BREAKING JAVASCRIPT CODE
      4. THIS BOOK'S INTENDED AUDIENCE
      5. HOW THIS BOOK IS STRUCTURED
      6. WHAT YOU NEED TO USE THIS BOOK
      7. CONVENTIONS
      8. SOURCE CODE
      9. ERRATA
      10. P2P.WROX.COM
    2. PART I: LAYING A SOLID FOUNDATION
      1. CHAPTER 1 PRACTICING SKILLFUL SOFTWARE ENGINEERING
        1. WRITING CODE THAT STARTS CORRECT
        2. WRITING CODE THAT STAYS CORRECT
        3. SUMMARY
      2. CHAPTER 2 TOOLING UP
        1. USING A TESTING FRAMEWORK
        2. USING A DEPENDENCY-INJECTION FRAMEWORK
        3. USING AN ASPECT TOOLKIT
        4. USING A CODE-CHECKING TOOL
        5. SUMMARY
      3. CHAPTER 3 CONSTRUCTING RELIABLE OBJECTS
        1. USING PRIMITIVES
        2. USING OBJECT LITERALS
        3. USING THE MODULE PATTERN
        4. USING OBJECT PROTOTYPES AND PROTOTYPAL INHERITANCE
        5. CREATING OBJECTS WITH NEW
        6. USING CLASSICAL INHERITANCE
        7. USING FUNCTIONAL INHERITANCE
        8. MONKEY-PATCHING
        9. SUMMARY
    3. PART II: TESTING PATTERN-BASED CODE
      1. CHAPTER 4 REVIEWING THE BENEFITS OF PATTERNS
        1. CASE STUDY
        2. PRODUCING MORE ELEGANT CODE BY USING A BROADER VOCABULARY
        3. PRODUCING RELIABLE CODE WITH WELL-ENGINEERED, WELL-TESTED BUILDING BLOCKS
        4. SUMMARY
      2. CHAPTER 5 ENSURING CORRECT USE OF THE CALLBACK PATTERN
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. AVOIDING PROBLEMS
        3. SUMMARY
      3. CHAPTER 6 ENSURING CORRECT USE OF THE PROMISE PATTERN
        1. UNDERSTANDING PROMISES THROUGH UNIT TESTS
        2. CHAINING PROMISES
        3. USING A PROMISE WRAPPER
        4. UNDERSTANDING STATES AND FATES
        5. DISTINGUISHING STANDARD PROMISES FROM JQUERY PROMISES
        6. SUMMARY
      4. CHAPTER 7 ENSURING CORRECT USE OF PARTIAL FUNCTION APPLICATION
        1. UNIT-TESTING A PARTIAL FUNCTION APPLICATION
        2. CREATING AN ASPECT FOR PARTIAL FUNCTION APPLICATION
        3. DISTINGUISHING BETWEEN PARTIAL FUNCTION APPLICATION AND CURRYING
        4. SUMMARY
      5. CHAPTER 8 ENSURING CORRECT USE OF THE MEMOIZATION PATTERN
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. ADDING MEMOIZATION WITH AOP
        3. SUMMARY
      6. CHAPTER 9 ENSURING CORRECT IMPLEMENTATION OF THE SINGLETON PATTERN
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. SUMMARY
      7. CHAPTER 10 ENSURING CORRECT IMPLEMENTATION OF THE FACTORY PATTERN
        1. WRITING UNIT TESTS FOR A FACTORY
        2. IMPLEMENTING THE FACTORY PATTERN
        3. CONSIDERING OTHER FACTORY TYPES
        4. SUMMARY
      8. CHAPTER 11 ENSURING CORRECT IMPLEMENTATION AND USE OF THE SANDBOX PATTERN
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. SUMMARY
      9. CHAPTER 12 ENSURING CORRECT IMPLEMENTATION OF THE DECORATOR PATTERN
        1. DEVELOPING A DECORATOR THE TEST-DRIVEN WAY
        2. SUMMARY
      10. CHAPTER 13 ENSURING CORRECT IMPLEMENTATION OF THE STRATEGY PATTERN
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. SUMMARY
      11. CHAPTER 14 ENSURING CORRECT IMPLEMENTATION OF THE PROXY PATTERN
        1. DEVELOPING A PROXY THE TEST-DRIVEN WAY
        2. SUMMARY
      12. CHAPTER 15 ENSURING CORRECT IMPLEMENTATION OF CHAINABLE METHODS
        1. UNDERSTANDING THE PATTERN THROUGH UNIT TESTS
        2. CHAINING THEN
        3. SUMMARY
    4. PART III: TESTING AND WRITING WITH ADVANCED JAVASCRIPT FEATURES
      1. CHAPTER 16 CONFORMING TO INTERFACES IN AN INTERFACE-FREE LANGUAGE
        1. UNDERSTANDING THE BENEFITS OF INTERFACES
        2. UNDERSTANDING THE INTERFACE SEGREGATION PRINCIPLE
        3. USING TEST-DRIVEN DEVELOPMENT TO CREATE A CONTRACT REGISTRY
        4. SUMMARY:
      2. CHAPTER 17 ENSURING CORRECT ARGUMENT TYPES
        1. UNDERSTANDING THE OPPORTUNITIES AND RISKS POSED BY JAVASCRIPT’S TYPE-FREE PARAMETERS
        2. EXTENDING THE CONTRACTREGISTRY TO CHECK ARGUMENTS
        3. SUPPORTING CONTRACT LIBRARIES
        4. PUTTING IT ALL TOGETHER
        5. COMPARING THE ASPECT-ORIENTED SOLUTION TO A STATIC SOLUTION
        6. SUMMARY
      3. CHAPTER 18 ENSURING CORRECT USE OF CALL, APPLY, AND BIND
        1. EXPLORING HOW THIS IS BOUND
        2. CREATING AND TESTING CODE THAT USES CALL, APPLY, AND BIND
        3. SUMMARY
      4. CHAPTER 19 ENSURING CORRECT USE OF METHOD-BORROWING
        1. ENSURING THE BORROWING OBJECT IS SUITABLE
        2. ANTICIPATING SIDE EFFECTS ON THE BORROWER
        3. ANTICIPATING SIDE EFFECTS ON THE DONOR OBJECT
        4. SUMMARY
      5. CHAPTER 20 ENSURING CORRECT USE OF MIXINS
        1. CREATING AND USING MIXINS
        2. SUMMARY
      6. CHAPTER 21 TESTING ADVANCED PROGRAM ARCHITECTURES
        1. ENSURING RELIABLE USE OF THE OBSERVER PATTERN
        2. ENSURING RELIABLE USE OF THE MEDIATOR PATTERN
        3. SUMMARY
    5. PART IV: SPECIAL SUBJECTS IN TESTING
      1. CHAPTER 22 TESTING DOM ACCESS
        1. UNIT-TESTING UI
        2. OPTIMIZING YOUR CODE WITH A PROFILER
        3. SUMMARY
      2. CHAPTER 23 ENSURING CONFORMANCE TO STANDARDS
        1. USING ESLINT
        2. ENFORCING ARCHITECTURAL DIVISIONS
        3. SUMMARY
    6. PART V: SUMMARY
      1. CHAPTER 24 SUMMARY OF THE PRINCIPLES OF TEST-DRIVEN DEVELOPMENT
        1. RECALLING WHY TEST-DRIVEN DEVELOPMENT IS WORTHWHILE
        2. PRACTICING TEST-DRIVEN DEVELOPMENT
        3. SUMMARY
      2. CHAPTER 25 SUMMARY OF JAVASCRIPT IDIOMS IN THIS BOOK
        1. REVIEWING OBJECTS
        2. REVIEWING VARIABLES
        3. REVIEWING FUNCTIONS
        4. REVIEWING BOOLEAN OPERATIONS
        5. SUMMARY
    7. INDEX
    8. EULA