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

Questions

1.1. Classes as first-class objects: We saw that functions are first class objects, but did you know classes also are? (Though, of course, speaking of classes as objects does sound weird...) Study this example and see what makes it tick! Be careful: there's some purposefully weird code in it:

      const makeSaluteClass = term =>          class {              constructor(x) {                 this.x = x;              }                      salute(y) {                 console.log(`${this.x} says "${term}" to ${y}`);               }          };      const Spanish = makeSaluteClass("HOLA");      new Spanish("ALFA").salute("BETA");      // ALFA says "HOLA" to BETA      new (makeSaluteClass("HELLO"))("GAMMA").salute("DELTA");      // GAMMA says "HELLO" to DELTA      const fullSalute = (c, x, y) => new c(x).salute(y);      const French = makeSaluteClass("BON JOUR"); fullSalute(French, ...
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