Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Stubbing

Here, we will look at a use case that is similar in some aspects to using a polyfill: having a function do different work depending on the environment. The idea is to perform stubbing, an idea that comes from testing that involves replacing a function with another that does a simpler job, instead of doing the actual work.

Stubbing is commonly used with logging functions. You may want the application to perform detailed logging when in development, but not to say a peep when in production. A common solution would be to write something along the lines of the following:

let myLog = someText => {  if (DEVELOPMENT) {    console.log(someText); // or some other way of logging  } else {    // do nothing  }}

This works, but as in the example of Ajax ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content