Spencer, Lawrence D.

Reliable JavaScript : How to Code Safely in the World's Most Dangerous Language. - 1st ed. - 1 online resource (530 pages)

Intro -- Reliable JavaScript® -- Contents -- Introduction -- Part I: Laying a Solid Foundation -- Chapter 1: Practicing Skillful Software -- Writing Code That Starts Correct -- Mastering the Features of JavaScript -- Case Study: D3.js -- JavaScript Is Single-Threaded -- Avoiding JavaScript's Pitfalls in Larger Systems -- Scripts Are Not Modules -- Nested Functions Control Scope -- Coding by Contract -- Applying the Principles of Software Engineering -- The SOLID Principles -- The DRY Principle -- Writing Code That Stays Correct -- Investing for the Future with Unit Tests -- Practicing Test-Driven Development -- Engineering Your Code to Be Easy to Test -- Summary -- Chapter 2: Tooling Up -- Using a Testing Framework -- Identifying Incorrect Code -- Designing for Testability -- Writing the Minimum Required Code -- Safe Maintenance and Refactoring -- Runnable Specification -- Current Open-Source and Commercial Frameworks -- QUnit -- D.O.H. -- Introducing Jasmine -- Suites and Specs -- Expectations and Matchers -- Spies -- Using a Dependency-Injection Framework -- What Is Dependency Injection? -- Making Your Code More Reliable with Dependency Injection -- Mastering Dependency Injection -- Case Study: Writing a Lightweight Dependency-Injection Framework -- Using a Dependency-Injection Framework -- Current Dependency-Injection Frameworks -- RequireJS -- AngularJS -- Using an Aspect Toolkit -- Case Study: Caching with and without AOP -- Implementing Caching without AOP -- Making Your Code More Reliable with AOP -- Case Study: Building the Aop.js Module -- Other AOP Libraries -- AspectJS -- AopJS jQuery Plugin -- YUI's Do Class -- Conclusion -- Using a Code-Checking Tool -- Making Your Code More Reliable with Linting Tools -- Introducing JSHint -- Using JSHint -- If You Don't Run It, Bugs Will Come -- Alternatives to JSHint -- JSLint -- ESLint. Strict Mode -- Summary -- Chapter 3: Constructing Reliable Objects -- Using Primitives -- Using Object Literals -- Using the Module Pattern -- Creating Modules-at-Will -- Creating Immediate-Execution Modules -- Creating Reliable Modules -- Using Object Prototypes and Prototypal Inheritance -- The Default Object Prototype -- Prototypal Inheritance -- Prototype Chains -- Creating Objects with New -- The new Object Creation Pattern -- Potential for Bad Things to Happen -- Enforcing the Use of new -- Using Classical Inheritance -- Emulating Classical Inheritance -- Repetition Killed the Kangaroo -- Using Functional Inheritance -- Monkey-Patching -- Summary -- Part II: Testing Pattern-Based Code -- Chapter 4: Reviewing the Benefits of Patterns -- Case Study -- Producing More Elegant Code by Using a Broader Vocabulary -- Producing Reliable Code with Well-Engineered, Well-Tested Building Blocks -- Summary -- Chapter 5: Ensuring Correct Use of the Call back Pattern -- Understanding the Pattern Through Unit Tests -- Writing and Testing Code That Uses Callback Functions -- Writing and Testing Callback Functions -- Avoiding Problems -- Flattening the Callback Arrow -- Minding this -- Summary -- Chapter 6: Ensuring Correct Use of the Promise Pattern -- Understanding Promises Through Unit Tests -- Using a Promise -- Constructing and Returning a Promise -- Testing an XMLHttpRequest -- Chaining Promises -- Using a Promise Wrapper -- Understanding States and Fates -- Distinguishing Standard Promises from jQuery Promises -- Summary -- Chapter 7: Ensuring Correct Use of Partial Function Application -- Unit-Testing a Partial Function Application -- Creating an Aspect for Partial Function Application -- Distinguishing Between Partial Function Application and Currying -- Currying -- Partial Function Application -- Summary. Chapter 8: Ensuring Correct Use of the Memoization Pattern -- Understanding the Pattern Through Unit Tests -- Adding Memoization with AOP -- Creating the Memoization Aspect -- Applying the returnValueCache Aspect to restaurantApi -- Summary -- Chapter 9: Ensuring Correct Implementation of the Singleton Pattern -- Understanding the Pattern Through Unit Tests -- Implementing a Singleton Shared Cache with an Object Literal -- Implementing a Singleton Shared Cache with a Module -- Summary -- Chapter 10: Ensuring Correct Implementation of the Factory Pattern -- Writing Unit Tests for a Factory -- Implementing the Factory Pattern -- Considering Other Factory Types -- Summary -- Chapter 11: Ensuring Correct Implementation and Use of the Sandbox Pattern -- Understanding the Pattern Through Unit Tests -- Creating a Widget Sandbox -- Instantiating a Widget Sandbox -- Providing Tools to the Widget via the Sandbox -- Creating and Testing Sandbox Tools -- Creating Functions for Use with a Sandbox -- Summary -- Chapter 12: Ensuring Correct Implementation of the Decorator Pattern -- Developing a Decorator the Test-Driven Way -- Writing a Fake for the Decorated Object -- Writing Tests for Pass-Through of Errors -- Writing a Do-Nothing Decorator -- Adding Pass-Through Functionality to the Decorator -- Verifying Pass-Through of Successes -- Adding the Decorator's Features -- Generalizing the Decorator -- Summary -- Chapter 13: Ensuring Correct Implementation of the Strategy Pattern -- Understanding the Pattern Through Unit Tests -- Implementing the transportScheduler Without the Strategy Pattern -- Implementing the transportScheduler Using the Strategy Pattern -- Creating transportScheduler Using Test-Driven Development -- Creating a Strategy for Use with transportScheduler -- Summary -- Chapter 14: Ensuring Correct Implementation of the Proxy Pattern. Developing a Proxy the Test-Driven Way -- Summary -- Chapter 15: Ensuring Correct Implementation of Chainable Methods -- Understanding the Pattern Through Unit Tests -- Chaining then -- Summary -- Part III: Testing and Writing with Advanced JavaScript Features -- Chapter 16: Conforming to Interfaces in an Interface-Free Language -- Understanding the Benefits of Interfaces -- Understanding the Interface Segregation Principle -- Using Test-Driven Development to Create a Contract Registry -- Defining a Contract -- Determining Whether a Contract Is Fulfilled -- Asserting That a Contract Is Fulfilled -- Bypassing Contract Enforcement -- Creating an Aspect to Enforce a Contract on a Returned (Created) Object -- Summary -- Chapter 17: Ensuring Correct Argument Types -- Introduction -- Understanding the Opportunities and Risks Posed by JavaScript's Type-Free Parameters -- Extending the ContractRegistry to Check Arguments -- Scoping Out the Task -- Determining Whether Every Variable in a Set Fulfills Its Contract -- Asserting That Every Variable in a Set Fulfills Its Contract -- Packaging Argument-Checking in an Aspect -- Supporting Contract Libraries -- Putting It All Together -- Creating the Contracts Modules -- Creating the Application's ContractRegistry -- Bypassing Contracts for Production -- Comparing the Aspect-Oriented Solution to a Static Solution -- Considering the Advantages of TypeScript -- Considering the Advantages of Aspects -- Summary -- Chapter 18: Ensuring Correct Use of call, apply, and bind -- Exploring How this Is Bound -- Default Binding -- Default Binding and strict Mode -- Implicit Binding -- new Binding -- Explicit Binding -- Creating and Testing Code That Uses call, apply, and bind -- Using call and apply -- Creating an Array.prototype.forEach Polyfill Using Test-Driven Development -- Using bind -- Summary. Chapter 19: Ensuring the Correct Use of Method-Borrowing -- Ensuring the Borrowing Object Is Suitable -- Making the Borrowed Function Qualify the Borrower -- Attaching an Aspect to the Borrowed Object -- Using a borrow Method -- Adding an Object-Validator to the ContractRegistry -- Anticipating Side Effects on the Borrower -- Considering Side Effects from an Isolated Function -- Considering Side Effects from a Function That Calls Other Functions -- Anticipating Side Effects on the Donor Object -- Summary -- Chapter 20: Ensuring Correct Use of Mixins -- Creating and Using Mixins -- Creating and Using a Traditional Mixin -- Creating the extend Function Using Test-driven Development -- Creating a Traditional Mixin Using Test-driven Development -- Creating and Using a Functional Mixin -- Summary -- Chapter 21: Testing Advanced Program Architectures -- Ensuring Reliable Use of the Observer Pattern -- Examining the Observer Pattern -- Enhancing the Reliability of the Observer Pattern -- Ensuring Reliable Use of the Mediator Pattern -- Examining the Mediator Pattern -- Enhancing the Reliability of Mediator-Based Code -- Developing a Colleague -- Testing a Colleague -- Segregating the Mediator's Interfaces -- Deciding Where to Put the Contracts -- Ensuring the Colleague Gets a Mediator with the Expected Interface -- Developing a Mediator -- Testing the Mediator -- Summary -- Part IV: Special Subjects in Testing -- Chapter 22: Testing DOM Access -- Unit-Test ing UI -- Examining Difficult-to-Test UI Code -- Creating a UI Component Using TDD -- Testing Code That Changes the DOM -- Testing to Ensure Event Handlers Are Executed -- Keeping UI Tests from Being Brittle -- Optimizing Your Code with a Profiler -- Detecting Inefficiencies -- Avoiding Premature Optimization -- Summary -- Chapter 23: Ensuring Conformance to Standards -- Using ESLint. Installing ESLint.

9781119028741


COMPUTERS / Programming Languages / JavaScript.


Electronic books.

QA76.73.J39 -- .S646 2015eb

005.2/762