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

Adding missing functions

This idea of defining a function on the run, also allows us to write polyfills that provide otherwise missing functions. For example, let's say that instead of writing code like:

if (currentName.indexOf("Mr.") !== -1) {    // it's a man    ...}

You'd very much prefer using the newer, clearer way, and just write:

if (currentName.includes("Mr.")) {    // it's a man    ...}

What happens if your browser doesn't provide .includes()? Once again, we can define the appropriate function on the run, but only if needed. If .includes() is available, you need do nothing, but if it is missing, you then define a polyfill that will provide the very same workings.

You can find polyfills for many modern JS features at Mozilla's developer site. ...
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