Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Stubbing

This is a use case similar in some aspects to polyfill: having a function do different work depending on the environment. The idea is to do stubbing, an idea from testing, which means replacing a function with another that does a simpler job, instead of doing the actual work.

A common case is the usage of logging functions. You may want the application to do detailed logging when in development, but not to say a peep when in production. A common solution would be writing something along the lines of:

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

This works, but as in the example about Ajax detection, it does more work than it about Ajax detection, it ...

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 - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content