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

Currying with bind()

We can find a solution to currying by using the .bind() method. This allows us to fixate one argument (or more, if need be; we won't be needing that here, but later on, we will use it) and provide a function with that fixed argument. Of course, many libraries (such as Lodash, Underscore, Ramda, and more) provide this functionality, but we want to see how to implement that by ourselves.

Read more on .bind() at https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind -- it will be useful since we'll take advantage of this method more times in this chapter.

Our implementation is quite short but will require some explanation:

const curryByBind = fn =>    fn.length === 0 ? fn() : p => curryByBind(fn.bind(null, ...
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