Muutke küpsiste eelistusi

E-raamat: Reliable JavaScript - How to Code Safely in the World's Most Dangerous Language: How to Code Safely in the World's Most Dangerous Language [Wiley Online]

  • Formaat: 528 pages
  • Ilmumisaeg: 28-Aug-2015
  • Kirjastus: Wrox Press
  • ISBN-10: 1119209552
  • ISBN-13: 9781119209553
Teised raamatud teemal:
  • Wiley Online
  • Hind: 52,87 €*
  • * hind, mis tagab piiramatu üheaegsete kasutajate arvuga ligipääsu piiramatuks ajaks
  • Formaat: 528 pages
  • Ilmumisaeg: 28-Aug-2015
  • Kirjastus: Wrox Press
  • ISBN-10: 1119209552
  • ISBN-13: 9781119209553
Teised raamatud teemal:
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.
Introduction xxi
Part I: Laying A Solid Foundation
Chapter 1 Practicing Skillful Software
3(26)
Writing Code That Starts Correct
4(18)
Mastering the Features of JavaScript
4(12)
Case Study: D3.js
5(10)
JavaScript Is Single-Threaded
15(1)
Avoiding JavaScript's Pitfalls in Larger Systems
16(2)
Scripts Are Not Modules
16(1)
Nested Functions Control Scope
16(1)
Coding by Contract
17(1)
Applying the Principles of Software Engineering
18(4)
The SOLID Principles
18(3)
The DRY Principle
21(1)
Writing Code That Stays Correct
22(5)
Investing for the Future with Unit Tests
22(1)
Practicing Test-Driven Development
23(1)
Engineering Your Code to Be Easy to Test
24(3)
Summary
27(2)
Chapter 2 Tooling Up
29(52)
Using a Testing Framework
29(16)
Identifying Incorrect Code
33(2)
Designing for Testability
35(1)
Writing the Minimum Required Code
36(1)
Safe Maintenance and Refactoring
36(1)
Runnable Specification
37(1)
Current Open-Source and Commercial Frameworks
37(2)
QUnit
37(1)
D.O.H.
38(1)
Introducing Jasmine
39(6)
Suites and Specs
39(2)
Expectations and Matchers
41(1)
Spies
41(4)
Using a Dependency-Injection Framework
45(13)
What Is Dependency Injection?
45(1)
Making Your Code More Reliable with Dependency Injection
46(1)
Mastering Dependency Injection
47(1)
Case Study: Writing a Lightweight Dependency-Injection Framework
47(8)
Using a Dependency-Injection Framework
55(1)
Current Dependency-Injection Frameworks
56(2)
RequireJS
56(1)
AngularJS
57(1)
Using an Aspect Toolkit
58(15)
Case Study: Caching with and without AOP
58(2)
Implementing Caching without AOP
58(2)
Making Your Code More Reliable with AOP
60(1)
Case Study: Building the Aop.js Module
60(12)
Other AOP Libraries
72(1)
AspectJS
72(1)
AopJS jQuery Plugin
73(1)
YUI's Do Class
73(1)
Conclusion
73(1)
Using a Code-Checking Tool
73(7)
Making Your Code More Reliable with Linting Tools
74(2)
Introducing JSHint
76(3)
Using JSHint
76(3)
If You Don't Run It, Bugs Will Come
79(1)
Alternatives to JSHint
79(1)
JSLint
79(1)
ESLint
79(1)
Strict Mode
80(1)
Summary
80(1)
Chapter 3 Constructing Reliable Objects
81(26)
Using Primitives
81(2)
Using Object Literals
83(1)
Using the Module Pattern
84(3)
Creating Modules-at-Will
84(1)
Creating Immediate-Execution Modules
85(1)
Creating Reliable Modules
86(1)
Using Object Prototypes and Prototypal Inheritance
87(2)
The Default Object Prototype
87(1)
Prototypal Inheritance
88(1)
Prototype Chains
88(1)
Creating Objects with New
89(6)
The new Object Creation Pattern
89(6)
Potential for Bad Things to Happen
90(1)
Enforcing the Use of new
90(5)
Using Classical Inheritance
95(3)
Emulating Classical Inheritance
95(1)
Repetition Killed the Kangaroo
96(2)
Using Functional Inheritance
98(2)
Monkey-Patching
100(2)
Summary
102(5)
Part II: Testing Pattern-Based Code
Chapter 4 Reviewing The Benefits Of Patterns
107(4)
Case Study
107(1)
Producing More Elegant Code by Using a Broader Vocabulary
108(1)
Producing Reliable Code with Well-Engineered, Well-Tested Building Blocks
109(1)
Summary
110(1)
Chapter 5 Ensuring Correct Use Of The Callback Pattern
111(18)
Understanding the Pattern Through Unit Tests
112(9)
Writing and Testing Code That Uses Callback Functions
112(5)
Writing and Testing Callback Functions
117(4)
Avoiding Problems
121(7)
Flattening the Callback Arrow
121(2)
Minding this
123(5)
Summary
128(1)
Chapter 6 Ensuring Correct Use Of The Promise Pattern
129(16)
Understanding Promises Through Unit Tests
130(11)
Using a Promise
130(5)
Constructing and Returning a Promise
135(3)
Testing an XMLHttpRequest
138(3)
Chaining Promises
141(1)
Using a Promise Wrapper
142(1)
Understanding States and Fates
143(1)
Distinguishing Standard Promises from jQuery Promises
143(1)
Summary
143(2)
Chapter 7 Ensuring Correct Use Of Partial Function Application
145(6)
Unit-Testing a Partial Function Application
145(2)
Creating an Aspect for Partial Function Application
147(2)
Distinguishing Between Partial Function Application and Currying
149(1)
Currying
149(1)
Partial Function Application
149(1)
Summary
150(1)
Chapter 8 Ensuring Correct Use Of The Memoization Pattern
151(10)
Understanding the Pattern Through Unit Tests
152(3)
Adding Memoization with AOP
155(5)
Creating the Memoization Aspect
155(4)
Applying the returnValueCache Aspect to restaurantApi
159(1)
Summary
160(1)
Chapter 9 Ensuring Correct Implementation Of The Singleton Pattern
161(12)
Understanding the Pattern Through Unit Tests
162(8)
Implementing a Singleton Shared Cache with an Object Literal
162(4)
Implementing a Singleton Shared Cache with a Module
166(4)
Summary
170(3)
Chapter 10 Ensuring Correct Implementation Of The Factory Pattern
173(10)
Writing Unit Tests for a Factory
173(6)
Implementing the Factory Pattern
179(2)
Considering Other Factory Types
181(1)
Summary
181(2)
Chapter 11 Ensuring Correct Implementation And Use Of The Sandbox Pattern
183(22)
Understanding the Pattern Through Unit Tests
184(19)
Creating a Widget Sandbox
185(12)
Instantiating a Widget Sandbox
185(2)
Providing Tools to the Widget via the Sandbox
187(10)
Creating and Testing Sandbox Tools
197(4)
Creating Functions for Use with a Sandbox
201(2)
Summary
203(2)
Chapter 12 Ensuring Correct Implementation Of The Decorator Pattern
205(18)
Developing a Decorator the Test-Driven Way
207(15)
Writing a Fake for the Decorated Object
207(1)
Writing Tests for Pass-Through of Errors
208(1)
Writing a Do-Nothing Decorator
209(1)
Adding Pass-Through Functionality to the Decorator
210(3)
Verifying Pass-Through of Successes
213(2)
Adding the Decorator's Features
215(7)
Generalizing the Decorator
222(1)
Summary
222(1)
Chapter 13 Ensuring Correct Implementation Of The Strategy Pattern
223(16)
Understanding the Pattern Through Unit Tests
223(14)
Implementing the transportScheduler Without the Strategy Pattern
224(2)
Implementing the transportScheduler Using the Strategy Pattern
226(49)
Creating transportScheduler Using Test-Driven Development
227(8)
Creating a Strategy for Use with transportScheduler
235(2)
Summary
237(2)
Chapter 14 Ensuring Correct Implementation Of The Proxy Pattern
239(18)
Developing a Proxy the Test-Driven Way
240(16)
Summary
256(1)
Chapter 15 Ensuring Correct Implementation Of Chainable Methods
257(14)
Understanding the Pattern Through Unit Tests
259(7)
Chaining then
266(1)
Summary
267(4)
Part III: Testing And Writing With Advanced Javascript Features
Chapter 16 Conforming To Interfaces In An Interface-Free Language
271(18)
Understanding the Benefits of Interfaces
272(1)
Understanding the Interface Segregation Principle
273(2)
Using Test-Driven Development to Create a Contract Registry
275(13)
Defining a Contract
275(3)
Determining Whether a Contract Is Fulfilled
278(4)
Asserting That a Contract Is Fulfilled
282(1)
Bypassing Contract Enforcement
283(1)
Creating an Aspect to Enforce a Contract on a Returned (Created) Object
283(5)
Summary
288(1)
Chapter 17 Ensuring Correct Argument Types
289(22)
Introduction
289(1)
Understanding the Opportunities and Risks Posed by JavaScript's Type-Free Parameters
290(1)
Extending the ContractRegistry to Check Arguments
290(13)
Scoping Out the Task
291(1)
Determining Whether Every Variable in a Set Fulfills Its Contract
291(9)
Asserting That Every Variable in a Set Fulfills Its Contract
300(1)
Packaging Argument-Checking in an Aspect
301(2)
Supporting Contract Libraries
303(1)
Putting It All Together
303(4)
Creating the Contracts Modules
304(3)
Creating the Application's ContractRegistry
307(1)
Bypassing Contracts for Production
307(1)
Comparing the Aspect-Oriented Solution to a Static Solution
307(1)
Considering the Advantages of TypeScript
308(1)
Considering the Advantages of Aspects
308(1)
Summary
308(3)
Chapter 18 Ensuring Correct Use Of Call, Apply, And Bind
311(24)
Exploring How this Is Bound
312(5)
Default Binding
312(2)
Default Binding and strict Mode
313(1)
Implicit Binding
314(2)
new Binding
316(1)
Explicit Binding
317(1)
Creating and Testing Code That Uses call, apply, and bind
317(17)
Using call and apply
318(2)
Creating an Array.prototype.forEach Polyfill Using Test-Driven Development
320(9)
Using bind
329(5)
Summary
334(1)
Chapter 19 Ensuring The Correct Use Of Method-Borrowing
335(18)
Ensuring the Borrowing Object Is Suitable
336(7)
Making the Borrowed Function Qualify the Borrower
336(2)
Attaching an Aspect to the Borrowed Object
338(4)
Using a borrow() Method
342(1)
Adding an Object-Validator to the ContractRegistry
342(1)
Anticipating Side Effects on the Borrower
343(8)
Considering Side Effects from an Isolated Function
343(2)
Considering Side Effects from a Function That Calls Other Functions
345(6)
Anticipating Side Effects on the Donor Object
351(1)
Summary
351(2)
Chapter 20 Ensuring Correct Use Of Mixins
353(30)
Creating and Using Mixins
355(25)
Creating and Using a Traditional Mixin
356(17)
Creating the extend Function Using Test-driven Development
356(11)
Creating a Traditional Mixin Using Test-driven Development
367(6)
Creating and Using a Functional Mixin
373(7)
Summary
380(3)
Chapter 21 Testing Advanced Program Architectures
383(30)
Ensuring Reliable Use of the Observer Pattern
384(11)
Examining the Observer Pattern
384(7)
Enhancing the Reliability of the Observer Pattern
391(4)
Ensuring Reliable Use of the Mediator Pattern
395(15)
Examining the Mediator Pattern
396(1)
Enhancing the Reliability of Mediator-Based Code
397(17)
Developing a Colleague
398(1)
Testing a Colleague
399(3)
Segregating the Mediator's Interfaces
402(1)
Deciding Where to Put the Contracts
403(1)
Ensuring the Colleague Gets a Mediator with the Expected Interface
404(2)
Developing a Mediator
406(2)
Testing the Mediator
408(2)
Summary
410(3)
Part IV: Special Subjects In Testing
Chapter 22 Testing DOM Access
413(22)
Unit-Testing UI
414(11)
Examining Difficult-to-Test UI Code
414(2)
Creating a UI Component Using TDD
416(9)
Testing Code That Changes the DOM
418(4)
Testing to Ensure Event Handlers Are Executed
422(3)
Keeping UI Tests from Being Brittle
425(1)
Optimizing Your Code with a Profiler
425(8)
Detecting Inefficiencies
426(7)
Avoiding Premature Optimization
433(1)
Summary
433(2)
Chapter 23 Ensuring Conformance To Standards
435(30)
Using ESLint
436(13)
Installing ESLint
436(3)
Installing Node and npm
436(3)
Installing ESLint Using npm
439(1)
Running ESLint
439(5)
Executing ESLint on a Single File
442(1)
Executing ESLint on All the JavaScript Files in a Directory
443(1)
Enforcing Coding Standards with ESLint
444(5)
Creating a Custom ESLint Rule
445(3)
Running ESLint with Custom Rules
448(1)
Enforcing Architectural Divisions
449(11)
The Family-Secret Technique
450(2)
The Imprinting Technique
452(2)
The Mission Impossible Technique
454(5)
The Magic Wand Technique
459(1)
Do Not Use the Call Stack Technique
460(1)
Other Techniques
460(1)
Other Architectures
460(1)
Summary
460(5)
Part V: Summary
Chapter 24 Summary Of The Principles Of Test-Driven Development
465(10)
Recalling Why Test-Driven Development Is Worthwhile
465(1)
Practicing Test-Driven Development
466(1)
Writing Unit-Testable Code
466(1)
Mastering the Mechanics of Test-Driven Development
466(2)
Writing the Test Before the Code
467(1)
Keeping Your Tests DRY
467(1)
Testing Error Conditions First
467(1)
Testing the Simple before the Complex
467(1)
Being Specific
467(1)
Testing Just One Thing
468(1)
Your Test Data Are Just As Important As the Test
468(1)
Using Jasmine Effectively
468(1)
Testing the Patterns in This Book
468(5)
Testing Aspect-Oriented Programming
468(1)
Testing Object Construction
469(1)
Testing Callbacks
469(1)
Testing Promise-Based Code
469(1)
Testing a Partial Function Application
470(1)
Testing Memoization
470(1)
Testing a Singleton
470(1)
Testing a Factory Method
470(1)
Testing a Sandbox
470(1)
Testing the Decorator Pattern
471(1)
Testing the Strategy Pattern
471(1)
Testing the Proxy Pattern
471(1)
Testing Chainable Methods
471(1)
Testing Conformance to an Interface
472(1)
Testing the Use of call and apply
472(1)
Testing the Method-Borrowing Pattern
472(1)
Testing Mixins
472(1)
Testing Mediators and Observers
473(1)
Testing DOM Access
473(1)
Tests to Enforce Architectural Divisions
473(1)
Summary
473(2)
Chapter 25 Summary Of Javascript Idioms In This Book
475(14)
Reviewing Objects
475(2)
Object Properties May Be Added and Removed
476(1)
Objects May Be Used as a Dictionary
476(1)
Reviewing Variables
477(4)
Variable Declarations Are Hoisted
477(1)
Variables Have Function Scope
478(3)
Reviewing Functions
481(5)
Functions Are Objects
481(1)
Functions Declarations Are Hoisted
481(1)
Functions Don't Have Return Types
482(1)
Functions May Be Anonymous
482(1)
Functions May Be Nested
483(1)
Functions May Be Invoked with Any Number of Arguments
484(1)
Functions May Be Invoked Immediately
485(1)
Reviewing Boolean Operations
486(1)
Types May Be Coerced When Testing Equality
486(1)
Values May Be Truthy or Falsy
487(1)
Summary
487(2)
Index 489
About the authors

Larry Spencer leads an international team of developers at ScerIS, a software and services company near Boston. He has over 35 years' experience as an executive, developer, consultant, teacher, and frequent presenter at programming conferences.

Seth Richards has been crafting software professionally since 2002. His past work focused on web-based, enterprise-class geographic information system applications.

Visit us at wrox.com where you have access to free code samples, Programmer to Programmer forums, and discussions on the latest happenings in the industry from around the world.