CHAPTER 7 Ensuring Correct Use of Partial Function Application

WHAT’S IN THIS CHAPTER?            

  • Unit-testing a partial function application
  • Adding a partial function application to an existing object with an aspect
  • Distinguishing between a partial function application and currying

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at www.wrox.com/go/reliablejavascript on the Download Code tab and in the Chapter 7 download.

Occasionally, you will use a function that has several arguments, but some of those arguments will always have the same values. Rather than supplying those values over and over again, it can be convenient to create a new function that wraps the original, supplying the constant arguments and exposing the rest. This technique is called partial function application.

Because you build on a known-good function, the new function is exceptionally easy to unit-test, making it a true friend on the road to reliable JavaScript.

UNIT-TESTING A PARTIAL FUNCTION APPLICATION

The upcoming JavaScript conference will be filled with thousands of hungry developers—not hungry for opportunities to program, which they all have in abundance, but hungry for food. Being a quirky lot, many of them have dietary restrictions: Some are vegan, while others eat only pizza. The conference will be jam-packed with events and it will be important to the attendees that they waste no time finding food. The next job for you and your colleague, ...

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.