January 2020
Intermediate to advanced
470 pages
11h 13m
English
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 ...