Book Image

Functional Programming in JavaScript

By : Dan Mantyla
Book Image

Functional Programming in JavaScript

By: Dan Mantyla

Overview of this book

<p>This is a fast-paced guide that will help you to write real-world applications by utilizing a wide range of functional techniques and styles.</p> <p>The book first explores the core concepts of functional programming common to all functional languages, with examples of their use in JavaScript. It's followed by a comprehensive roundup of functional programming libraries for JavaScript that minimizes the burden of digging deep into JavaScript to expose a set of tools that makes functional programming not just possible but highly convenient. The book then rounds off with an overview of methods to effectively use and mix functional programming with object-oriented programming.</p>
Table of Contents (16 chapters)
Functional Programming in JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Common Functions for Functional Programming in JavaScript
Glossary of Terms
Index

JavaScript's object-oriented implementation – using prototypes


JavaScript is a class-less language. That's not to mean it is less fashionable or more blue-collar than other computer languages; class-less means it doesn't have a class structure in the same way that object-oriented languages do. Instead, it uses prototypes for inheritance.

Although this may be baffling to programmers with backgrounds in C++ and Java, prototype-based inheritance can be much more expressive than traditional inheritance. The following is a brief comparison between the differences between C++ and JavaScript:

C++

JavaScript

Strongly typed

Loosely typed

Static

Dynamic

Class-based

Prototype-based

Classes

Functions

Constructors

Functions

Methods

Functions

Inheritance

Before we go much further, let's make sure we fully understand the concept of inheritance in object-oriented programming. Class-based inheritance is demonstrated in the following pseudo-code:

class Polygon {
  int numSides;
  function init(n...