Puzzle Zeitvertreib Beste 4K Filme Beste Multimedia-Lernspiele % SALE %

Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language


Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language
50.05 CHF
Versandkostenfrei

Lieferzeit ca. 5 Tage

  • 10335310


Beschreibung

INTRODUCTION xxiPART I: LAYING A SOLID FOUNDATIONCHAPTER 1: PRACTICING SKILLFUL SOFTWARE 3Writing Code That Starts Correct 4Mastering the Features of JavaScript 4Case Study: D3.js 5JavaScript Is Single-Threaded 15Avoiding JavaScript's Pitfalls in Larger Systems 16Scripts Are Not Modules 16Nested Functions Control Scope 16Coding by Contract 17Applying the Principles of Software Engineering 18The SOLID Principles 18The DRY Principle 21Writing Code That Stays Correct 22Investing for the Future with Unit Tests 22Practicing Test-Driven Development 23Engineering Your Code to Be Easy to Test 24Summary 27CHAPTER 2: TOOLING UP 29Using a Testing Framework 29Identifying Incorrect Code 33Designing for Testability 35Writing the Minimum Required Code 36Safe Maintenance and Refactoring 36Runnable Specification 37Current Open-Source and Commercial Frameworks 37QUnit 37D.O.H. 38Introducing Jasmine 39Suites and Specs 39Expectations and Matchers 41Spies 41Using a Dependency-Injection Framework 45What Is Dependency Injection? 45Making Your Code More Reliable with Dependency Injection 46Mastering Dependency Injection 47Case Study: Writing a Lightweight Dependency-Injection Framework 47Using a Dependency-Injection Framework 55Current Dependency-Injection Frameworks 56RequireJS 56AngularJS 57Using an Aspect Toolkit 58Case Study: Caching with and without AOP 58Implementing Caching without AOP 58Making Your Code More Reliable with AOP 60Case Study: Building the Aop.js Module 60Other AOP Libraries 72AspectJS 72AopJS jQuery Plugin 73YUI's Do Class 73Conclusion 73Using a Code-Checking Tool 73Making Your Code More Reliable with Linting Tools 74Introducing JSHint 76Using JSHint 76If You Don't Run It, Bugs Will Come 79Alternatives to JSHint 79JSLint 79ESLint 79Strict Mode 80Summary 80CHAPTER 3: CONSTRUCTING RELIABLE OBJECTS 81Using Primitives 81Using Object Literals 83Using the Module Pattern 84Creating Modules?]at?]Will 84Creating Immediate?]Execution Modules 85Creating Reliable Modules 86Using Object Prototypes and Prototypal Inheritance 87The Default Object Prototype 87Prototypal Inheritance 88Prototype Chains 88Creating Objects with New 89The new Object Creation Pattern 89Potential for Bad Things to Happen 90Enforcing the Use of new 90Using Classical Inheritance 95Emulating Classical Inheritance 95Repetition Killed the Kangaroo 96Using Functional Inheritance 98Monkey?]Patching 100Summary 102PART II: TESTING PATTERN-BASED CODECHAPTER 4: REVIEWING THE BENEFITS OF PATTERNS 107Case Study 107Producing More Elegant Code by Using a Broader Vocabulary 108Producing Reliable Code with Well-Engineered, Well-Tested Building Blocks 109Summary 110CHAPTER 5: ENSURING CORRECT USE OF THE CALLBACK PATTERN 111Understanding the Pattern Through Unit Tests 112Writing and Testing Code That Uses Callback Functions 112Writing and Testing Callback Functions 117Avoiding Problems 121Flattening the Callback Arrow 121Minding this 123Summary 128CHAPTER 6: ENSURING CORRECT USE OF THE PROMISE PATTERN 129Understanding Promises Through Unit Tests 130Using a Promise 130Constructing and Returning a Promise 135Testing an XMLHttpRequest 138Chaining Promises 141Using a Promise Wrapper 142Understanding States and Fates 143Distinguishing Standard Promises from jQuery Promises 143Summary 143CHAPTER 7: ENSURING CORRECT USE OF PARTIAL FUNCTION APPLICATION 145Unit-Testing a Partial Function Application 145Creating an Aspect for Partial Function Application 147Distinguishing Between Partial Function Application and Currying 149Currying 149Partial Function Application 149Summary 150CHAPTER 8: ENSURING CORRECT USE OF THE MEMOIZATION PATTERN 151Understanding the Pattern Through Unit Tests 152Adding Memoization with AOP 155Creating the Memoization Aspect 155Applying the returnValueCache Aspect to restaurantApi 159Summary 160CHAPTER 9: ENSURING CORRECT IMPLEMENTATION OF THE SINGLETON PATTERN 161Understanding the Pattern Through Unit Tests 162Implementing a Singleton Shared Cache with an Object Literal 162Implementing a Singleton Shared Cache with a Module 166Summary 170CHAPTER 10: ENSURING CORRECT IMPLEMENTATION OF THE FACTORY PATTERN 173Writing Unit Tests for a Factory 173Implementing the Factory Pattern 179Considering Other Factory Types 181Summary 181CHAPTER 11: ENSURING CORRECT IMPLEMENTATION AND USE OF THE SANDBOX PATTERN 183Understanding the Pattern Through Unit Tests 184Creating a Widget Sandbox 185Instantiating a Widget Sandbox 185Providing Tools to the Widget via the Sandbox 187Creating and Testing Sandbox Tools 197Creating Functions for Use with a Sandbox 201Summary 203CHAPTER 12: ENSURING CORRECT IMPLEMENTATION OF THE DECORATOR PATTERN 205Developing a Decorator the Test?]Driven Way 207Writing a Fake for the Decorated Object 207Writing Tests for Pass?]Through of Errors 208Writing a Do?]Nothing Decorator 209Adding Pass?]Through Functionality to the Decorator 210Verifying Pass?]Through of Successes 213Adding the Decorator's Features 215Generalizing the Decorator 222Summary 222CHAPTER 13: ENSURING CORRECT IMPLEMENTATION OF THE STRATEGY PATTERN 223Understanding the Pattern Through Unit Tests 223Implementing the transportScheduler Without the Strategy Pattern 224Implementing the transportScheduler Using the Strategy Pattern 226Creating transportScheduler Using Test?]Driven Development 227Creating a Strategy for Use with transportScheduler 235Summary 237CHAPTER 14: ENSURING CORRECT IMPLEMENTATION OF THE PROXY PATTERN 239Developing a Proxy the Test?]Driven Way 240Summary 256CHAPTER 15: ENSURING CORRECT IMPLEMENTATION OF CHAINABLE METHODS 257Understanding the Pattern Through Unit Tests 259Chaining then 266Summary 267PART III: TESTING AND WRITING WITH ADVANCED JAVASCRIPT FEATURESCHAPTER 16: CONFORMING TO INTERFACES IN AN INTERFACE-FREE LANGUAGE 271Understanding the Benefits of Interfaces 272Understanding the Interface Segregation Principle 273Using Test-Driven Development to Create a Contract Registry 275Defining a Contract 275Determining Whether a Contract Is Fulfilled 278Asserting That a Contract Is Fulfi lled 282Bypassing Contract Enforcement 283Creating an Aspect to Enforce a Contract on a Returned (Created) Object 283Summary 288CHAPTER 17: ENSURING CORRECT ARGUMENT TYPES 289Introduction 289Understanding the Opportunities and Risks Posed by JavaScript's Type-Free Parameters 290Extending the ContractRegistry to Check Arguments 290Scoping Out the Task 291Determining Whether Every Variable in a Set Fulfi lls Its Contract 291Asserting That Every Variable in a Set Fulfi lls Its Contract 300Packaging Argument-Checking in an Aspect 301Supporting Contract Libraries 303Putting It All Together 303Creating the Contracts Modules 304Creating the Application's ContractRegistry 307Bypassing Contracts for Production 307Comparing the Aspect-Oriented Solution to a Static Solution 307Considering the Advantages of TypeScript 308Considering the Advantages of Aspects 308Summary 308CHAPTER 18: ENSURING CORRECT USE OF CALL, APPLY, AND BIND 311Exploring How this Is Bound 312Default Binding 312Default Binding and strict Mode 313Implicit Binding 314new Binding 316Explicit Binding 317Creating and Testing Code That Uses call, apply, and bind 317Using call and apply 318Creating an Array.prototype.forEach Polyfill Using Test-Driven Development 320Using bind 329Summary 334CHAPTER 19: ENSURING THE CORRECT USE OF METHODBORROWING 335Ensuring the Borrowing Object Is Suitable 336Making the Borrowed Function Qualify the Borrower 336Attaching an Aspect to the Borrowed Object 338Using a borrow() Method 342Adding an Object?]Validator to the ContractRegistry 342Anticipating Side Effects on the Borrower 343Considering Side Effects from an Isolated Function 343Considering Side Effects from a Function That Calls Other Functions 345Anticipating Side Effects on the Donor Object 351Summary 351CHAPTER 20: ENSURING CORRECT USE OF MIXINS 353Creating and Using Mixins 355Creating and Using a Traditional Mixin 356Creating the extend Function Using Test?]driven Development 356Creating a Traditional Mixin Using Test?]driven Development 367Creating and Using a Functional Mixin 373Summary 380CHAPTER 21: TESTING ADVANCED PROGRAM ARCHITECTURES 383Ensuring Reliable Use of the Observer Pattern 384Examining the Observer Pattern 384Enhancing the Reliability of the Observer Pattern 391Ensuring Reliable Use of the Mediator Pattern 395Examining the Mediator Pattern 396Enhancing the Reliability of Mediator-Based Code 397Developing a Colleague 398Testing a Colleague 399Segregating the Mediator's Interfaces 402Deciding Where to Put the Contracts 403Ensuring the Colleague Gets a Mediator with the Expected Interface 404Developing a Mediator 406Testing the Mediator 408Summary 410PART IV: SPECIAL SUBJECTS IN TESTINGCHAPTER 22: TESTING ADVANCED PROGRAM ARCHITECTURES 383Ensuring Reliable Use of the Observer Pattern 384Examining the Observer Pattern 384Enhancing the Reliability of the Observer Pattern 391Ensuring Reliable Use of the Mediator Pattern 395Examining the Mediator Pattern 396Enhancing the Reliability of Mediator-Based Code 397Developing a Colleague 398Testing a Colleague 399Segregating the Mediator's Interfaces 402Deciding Where to Put the Contracts 403Ensuring the Colleague Gets a Mediator with the Expected Interface 404Developing a Mediator 406Testing the Mediator 408Summary 410CHAPTER 23: ENSURING CONFORMANCE TO STANDARDS 435Using ESLint 436Installing ESLint 436Installing Node and npm 436Installing ESLint Using npm 439Running ESLint 439Executing ESLint on a Single File 442Executing ESLint on All the JavaScript Files in a Directory 443Enforcing Coding Standards with ESLint 444Creating a Custom ESLint Rule 445Running ESLint with Custom Rules 448Enforcing Architectural Divisions 449The Family-Secret Technique 450The Imprinting Technique 452The Mission Impossible Technique 454The Magic Wand Technique 459Do Not Use the Call Stack Technique 460Other Techniques 460Other Architectures 460Summary 460PART V: SUMMARYCHAPTER 24: SUMMARY OF THE PRINCIPLES OF TEST-DRIVEN DEVELOPMENT 465Recalling Why Test-Driven Development Is Worthwhile 465Practicing Test-Driven Development 466Writing Unit-Testable Code 466Mastering the Mechanics of Test-Driven Development 466Writing the Test Before the Code 467Keeping Your Tests DRY 467Testing Error Conditions First 467Testing the Simple before the Complex 467Being Specifi c 467Testing Just One Thing 468Your Test Data Are Just As Important As the Test 468Using Jasmine Effectively 468Testing the Patterns in This Book 468Testing Aspect-Oriented Programming 468Testing Object Construction 469Testing Callbacks 469Testing Promise-Based Code 469Testing a Partial Function Application 470Testing Memoization 470Testing a Singleton 470Testing a Factory Method 470Testing a Sandbox 470Testing the Decorator Pattern 471Testing the Strategy Pattern 471Testing the Proxy Pattern 471Testing Chainable Methods 471Testing Conformance to an Interface 472Testing the Use of call and apply 472Testing the Method-Borrowing Pattern 472Testing Mixins 472Testing Mediators and Observers 473Testing DOM Access 473Tests to Enforce Architectural Divisions 473Summary 473CHAPTER 25: SUMMARY OF JAVASCRIPT IDIOMS IN THIS BOOK 475Reviewing Objects 475Object Properties May Be Added and Removed 476Objects May Be Used as a Dictionary 476Reviewing Variables 477Variable Declarations Are Hoisted 477Variables Have Function Scope 478Reviewing Functions 481Functions Are Objects 481Functions Declarations Are Hoisted 481Functions Don't Have Return Types 482Functions May Be Anonymous 482Functions May Be Nested 483Functions May Be Invoked with Any Number of Arguments 484Functions May Be Invoked Immediately 485Reviewing Boolean Operations 486Types May Be Coerced When Testing Equality 486Values May Be Truthy or Falsy 487Summary 487INDEX 489

Eigenschaften

Breite: 188
Gewicht: 901 g
Höhe: 235
Länge: 24
Seiten: 528
Sprachen: Englisch
Autor: Lawrence Spencer, Seth Richards

Bewertung

Bewertungen werden nach Überprüfung freigeschaltet.

Die mit einem * markierten Felder sind Pflichtfelder.

Ich habe die Datenschutzbestimmungen zur Kenntnis genommen.

Zuletzt angesehen

eUniverse.ch - zur Startseite wechseln © 2021 Nova Online Media Retailing GmbH