CHAPTER 11 Ensuring Correct Implementation and Use of the Sandbox Pattern
WHAT’S IN THIS CHAPTER?
- Using the Sandbox Pattern to create loosely coupled code
- Implementing the Sandbox Pattern using test-driven development
- Understanding how the Sandbox Pattern controls access to resources and functionality
- Writing and testing code that will be isolated within a sandbox
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
You can find the wrox.com code downloads for this chapter at www.wrox.com/go/reliablejavascript
on the Download Code tab. The files are in the Chapter 11 download and are individually named according to the filenames noted throughout this chapter.
In his book JavaScript Patterns (O’Reilly, 2010), Stoyan Stefanov presents the Sandbox Pattern as a solution to some of the drawbacks of the practice of namespacing in JavaScript. In particular, he states that the Sandbox Pattern alleviates the reliance on a single global variable for the application and reduces the proliferation of long, dotted names to type and resolve at run time. While the Sandbox Pattern certainly does both of those things, we’re most interested in another characteristic he mentions: the creation of an environment for modules to “play” in without impacting other modules and their sandboxes.
This chapter will use test-driven development to create an implementation of the Sandbox Pattern similar to the pattern presented in Stefanov’s book. The implementation will focus on creating an extendable sandbox, ...
Get Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.