Mastering JavaScript Design Patterns - Second Edition

Book description

Write reliable code to create powerful applications by mastering advanced JavaScript design patterns

About This Book

  • Learn how to use tried and true software design methodologies to enhance your JavaScript code

  • Discover robust JavaScript implementations of classic and advanced design patterns

  • Packed with easy-to-follow examples that can be used to create reusable code and extensible designs

  • Who This Book Is For

    This book is ideal for JavaScript developers who want to gain expertise in object-oriented programming with JavaScript and the new capabilities of ES-2015 to improve their web development skills and build professional-quality web applications.

    What You Will Learn

  • Harness the power of patterns for tasks ranging from application building to code testing

  • Rethink and revitalize your code with the use of functional patterns

  • Improve the way you organize your code

  • Build large-scale apps seamlessly with the help of reactive patterns

  • Identify the best use cases for microservices

  • Get to grips with creational, behavioral, and structural design patterns

  • Explore advanced design patterns including dependency injection

  • In Detail

    With the recent release of ES-2015, there are several new object-oriented features and functions introduced in JavaScript. These new features enhance the capabilities of JavaScript to utilize design patterns and software design methodologies to write powerful code.

    Through this book, you will explore how design patterns can help you improve and organize your JavaScript code. You’ll get to grips with creational, structural and behavioral patterns as you discover how to put them to work in different scenarios. Then, you'll get a deeper look at patterns used in functional programming, as well as model view patterns and patterns to build web applications.

    This updated edition will also delve into reactive design patterns and microservices as they are a growing phenomenon in the world of web development. You will also find patterns to improve the testability of your code using mock objects, mocking frameworks, and monkey patching. We’ll also show you some advanced patterns including dependency injection and live post processing.

    By the end of the book, you'll be saved of a lot of trial and error and developmental headaches, and you will be on the road to becoming a JavaScript expert.

    Style and approach

    Packed with several real-world use cases, this book shows you through step-by-step instructions how to implement the advanced object-oriented programming features to build sophisticated web applications that promote scalability and reusability.

    Table of contents

    1. Mastering JavaScript Design Patterns Second Edition
      1. Table of Contents
      2. Mastering JavaScript Design Patterns Second Edition
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Designing for Fun and Profit
        1. The road to JavaScript
          1. The early days
          2. A pause
          3. The way of GMail
          4. JavaScript everywhere
        2. What is a design pattern?
        3. Anti-patterns
        4. Summary
      9. I. Classical Design Patterns
        1. 2. Organizing Code
          1. Chunks of code
          2. What's the matter with global scope anyway?
          3. Objects in JavaScript
          4. Build me a prototype
          5. Inheritance
          6. Modules
          7. ECMAScript 2015 classes and modules
          8. Best practices and troubleshooting
          9. Summary
        2. 3. Creational Patterns
          1. Abstract factory
            1. Implementation
          2. Builder
            1. Implementation
          3. Factory method
            1. Implementation
          4. Singleton
            1. Implementation
            2. Disadvantages
          5. Prototype
            1. Implementation
          6. Tips and tricks
          7. Summary
        3. 4. Structural Patterns
          1. Adapter
            1. Implementation
          2. Bridge
            1. Implementation
          3. Composite
            1. Example
            2. Implementation
          4. Decorator
            1. Implementation
          5. Façade
            1. Implementation
          6. Flyweight
            1. Implementation
          7. Proxy
            1. Implementation
          8. Hints and tips
          9. Summary
        4. 5. Behavioral Patterns
          1. Chain of responsibility
            1. Implementation
          2. Command
            1. Command message
            2. Invoker
            3. Receiver
          3. Interpreter
            1. Example
            2. Implementation
          4. Iterator
            1. Implementation
            2. ECMAScript 2015 iterators
          5. Mediator
            1. Implementation
          6. Memento
            1. Implementation
          7. Observer
            1. Implementation
          8. State
            1. Implementation
          9. Strategy
            1. Implementation
          10. Template method
            1. Implementation
          11. Visitor
          12. Hints and tips
          13. Summary
      10. II. Other Patterns
        1. 6. Functional Programming
          1. Functional functions are side-effect-free
          2. Function passing
            1. Implementation
          3. Filters and pipes
            1. Implementation
          4. Accumulators
            1. Implementation
          5. Memoization
            1. Implementation
          6. Immutability
          7. Lazy instantiation
            1. Implementation
          8. Hints and tips
          9. Summary
        2. 7. Reactive Programming
          1. Application state changes
          2. Streams
          3. Filtering streams
          4. Merging streams
          5. Streams for multiplexing
          6. Hints and tips
          7. Summary
        3. 8. Application Patterns
          1. First, some history
          2. Model View Controller
            1. MVC code
          3. Model View Presenter
            1. MVP code
          4. Model View ViewModel
            1. MVVM code
            2. A better way to transfer changes between the model and the view
            3. Observing view changes
          5. Tips and tricks
          6. Summary
        4. 9. Web Patterns
          1. Sending JavaScript
            1. Combining files
            2. Minification
            3. Content Delivery Networks
          2. Plugins
            1. jQuery
            2. d3
          3. Doing two things at once – multithreading
          4. Circuit breaker pattern
            1. Back-off
            2. Degraded application behavior
          5. Promise pattern
          6. Hints and tips
          7. Summary
        5. 10. Messaging Patterns
          1. What's a message anyway?
            1. Commands
            2. Events
          2. Request-reply
          3. Publish-subscribe
            1. Fan out and in
          4. Dead letter queues
            1. Message replay
            2. Pipes and filters
            3. Versioning messages
          5. Hints and tips
          6. Summary
        6. 11. Microservices
          1. Façade
          2. Service selector
          3. Aggregate services
          4. Pipeline
          5. Message upgrader
          6. Failure patterns
            1. Service degradation
            2. Message storage
            3. Message replay
            4. Indempotence of message handling
          7. Hints and tips
          8. Summary
        7. 12. Patterns for Testing
          1. The testing pyramid
          2. Testing in the small with unit tests
          3. Arrange-Act-Assert
            1. Assert
          4. Fake objects
          5. Test spies
          6. Stubs
          7. Mock
          8. Monkey patching
          9. Interacting with the user interface
            1. Browser testing
            2. Faking the DOM
            3. Wrapping the manipulation
          10. Tips and tricks
          11. Summary
        8. 13. Advanced Patterns
          1. Dependency injection
          2. Live post processing
          3. Aspect oriented programming
          4. Mixins
          5. Macros
          6. Tips and tricks
          7. Summary
        9. 14. ECMAScript-2015/2016 Solutions Today
          1. TypeScript
            1. Decorators
            2. Async/Await
            3. Typing
          2. BabelJS
            1. Classes
            2. Default parameters
            3. Template literals
            4. Block bindings with let
            5. In production
          3. Tips and tricks
          4. Summary
      11. Index

    Product information

    • Title: Mastering JavaScript Design Patterns - Second Edition
    • Author(s): Simon Timms
    • Release date: June 2016
    • Publisher(s): Packt Publishing
    • ISBN: 9781785882166