Home Page Icon
Home Page
Table of Contents for
Functional JavaScript
Close
Functional JavaScript
by Michael Fogus
Functional JavaScript
Functional JavaScript
Dedication
Foreword by Jeremy Ashkenas
Foreword by Steve Vinoski
Preface
What Is Underscore?
Getting Underscore
Using Underscore
The Source Code for Functional JavaScript
Running the Code in This Book
Notational Conventions
Whom Functional JavaScript Is Written For
A Roadmap for Functional JavaScript
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
1. Introducing Functional JavaScript
The Case for JavaScript
Some Limitations of JavaScript
Getting Started with Functional Programming
Why Functional Programming Matters
Functions as Units of Abstraction
Encapsulation and Hiding
Functions as Units of Behavior
Data as Abstraction
A Taste of Functional JavaScript
On Speed
The Case for Underscore
Summary
2. First-Class Functions and Applicative Programming
Functions as First-Class Things
JavaScript’s Multiple Paradigms
Imperative programming
Prototype-based object-oriented programming
Metaprogramming
Applicative Programming
Collection-Centric Programming
Other Examples of Applicative Programming
reduceRight
find
reject
all
any
sortBy, groupBy, and countBy
Defining a Few Applicative Functions
Data Thinking
“Table-Like” Data
Summary
3. Variable Scope and Closures
Global Scope
Lexical Scope
Dynamic Scope
JavaScript’s Dynamic Scope
Function Scope
Closures
Simulating Closures
Free variables
Shadowing
Using Closures
Closures as an Abstraction
Summary
4. Higher-Order Functions
Functions That Take Other Functions
Thinking About Passing Functions: max, finder, and best
Tightening it up a bit
More Thinking About Passing Functions: repeat, repeatedly, and iterateUntil
Use functions, not values
I said, “Use functions, not values”
Functions That Return Other Functions
Capturing Arguments to Higher-Order Functions
Capturing Variables for Great Good
Take care when mutating values
A Function to Guard Against Nonexistence: fnull
Putting It All Together: Object Validators
Summary
5. Function-Building Functions
The Essence of Functional Composition
Mutation Is a Low-Level Operation
Currying
To Curry Right, or To Curry Left
Automatically Currying Parameters
Building new functions using currying
Currying three parameters to implement HTML hex color builders
Currying for Fluent APIs
The Disadvantages of Currying in JavaScript
Partial Application
Partially Applying One and Two Known Arguments
Partially Applying an Arbitrary Number of Arguments
Partial Application in Action: Preconditions
Stitching Functions End-to-End with Compose
Pre- and Postconditions Using Composition
Summary
6. Recursion
Self-Absorbed Functions (Functions That Call Themselves)
Graph Walking with Recursion
Depth-First Self-Recursive Search with Memory
Tail (self-)recursion
Recursion and Composing Functions: Conjoin and Disjoin
Codependent Functions (Functions Calling Other Functions That Call Back)
Deep Cloning with Recursion
Walking Nested Arrays
Too Much Recursion!
Generators
The Trampoline Principle and Callbacks
Recursion Is a Low-Level Operation
Summary
7. Purity, Immutability, and Policies for Change
Purity
The Relationship Between Purity and Testing
Separating the Pure from the Impure
Property-Testing Impure Functions
Purity and the Relationship to Referential Transparency
Purity and the Relationship to Idempotence
Immutability
If a Tree Falls in the Woods, Does It Make a Sound?
Immutability and the Relationship to Recursion
Defensive Freezing and Cloning
Observing Immutability at the Function Level
Observing Immutability in Objects
Objects Are Often a Low-Level Operation
Policies for Controlling Change
Summary
8. Flow-Based Programming
Chaining
A Lazy Chain
Promises
Pipelining
Data Flow versus Control Flow
Finding a Common Shape
A Function to Simplify Action Creation
Summary
9. Programming Without Class
Data Orientation
Building Toward Functions
Mixins
Core Prototype Munging
Class Hierarchies
Changing Hierarchies
Flattening the Hierarchy with Mixins
New Semantics via Mixin Extension
New Types via Mixin Mixing
Methods Are Low-Level Operations
}).call(“Finis”);
A. Functional JavaScript in the Wild
Functional Libraries for JavaScript
Functional JavaScript
Underscore-contrib
RxJS
Bilby
allong.es
Other Functional Libraries
Functional Programming Languages Targeting JavaScript
ClojureScript
CoffeeScript
Roy
Elm
B. Annotated Bibliography
Papers/Books/Blog Posts/Talks
Presentations
Blog Posts
Journal Articles
Index
About the Author
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Dedication
Functional JavaScript
Michael Fogus
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset