Book Image

Mastering JavaScript Design Patterns - Second Edition

By : Simon Timms
Book Image

Mastering JavaScript Design Patterns - Second Edition

By: Simon Timms

Overview of this book

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.
Table of Contents (5 chapters)

What this book covers

This book is divided into two main halves, each of which contains a number of chapters. The first half of the book, which we'll refer to as Part 1, covers the classical design patterns, which are found in the GoF book.

Chapter 1, Designing for Fun and Profit, introduces what design patterns are and why we are interested in using design patterns. We will also talk about some of the history of JavaScript to give you a historical context.

Chapter 2, Organizing Code, looks at how to create the classical structures that are used to organize code, namespaces, or modules and classes, as JavaScript lacks these constructs as first class citizens.

Chapter 3, Creational Patterns, covers the creational patterns outlined in the Gang of Four book. We'll discuss how these patterns apply to JavaScript, as opposed to the languages that were popular at the time when the Gang of Four wrote their book.

Chapter 4, Structural Patterns, looks at creational patterns. We'll examine the structural patterns from the Gang of Four book.

Chapter 5, Behavioral Patterns, discusses behavioral patterns. These are the final set of patterns from the Gang of Four book that we'll examine. These patterns govern different ways to link classes together.

Part 2 looks at patterns that are either not covered in the GoF book or that are specific to JavaScript.

Chapter 6, Functional Programming, covers some of the patterns that can be found in functional programming languages. We'll look at how these patterns can be used in JavaScript to improve code.

Chapter 7, Reactive Programming, explores the problems associated with the callback model of programming in JavaScript. It presents Reactive programming, a stream-based approach to events, as a possible solution.

Chapter 8, Application Patterns, examines the confusing variety of different patterns to create single page applications. We'll provide clarity and look at how to use libraries which use each of the existing patterns, as well as create our own lightweight framework.

Chapter 9, Web Patterns, looks at a number of patterns that have specific applicability to web applications. We'll also look at some patterns around deploying code to remote runtimes, such as the browser.

Chapter 10, Messaging Patterns, covers how messaging is a powerful technique to communicate inside and even between applications. In this chapter, we'll look at some common structures around messaging and discuss why messaging is so useful.

Chapter 11, Microservices, covers microservices, which are growing in popularity at a tremendous rate. This chapter examines the ideas behind this approach to programming and suggests a number of patterns to keep in mind when building using this approach.

Chapter 12, Patterns for Testing, discusses how building software is hard, and how building good software is doubly so. This chapter provides some patterns which can make the testing process a little bit easier.

Chapter 13, Advanced Patterns, explains how some patterns such as aspect-oriented programming are rarely applied in JavaScript. We'll look at how these patterns can be applied in JavaScript and discuss whether we should apply them.

Chapter 14, ECMAScript-2015/2016 Solutions Today, covers some of the tools available to allow you to use features from future versions of JavaScript today. We'll examine Microsoft's TypeScript as well as Traceur.