更新时间:2021-07-02 22:41:47
封面
版权信息
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Becoming Functional - Several Questions
What is Functional Programming?
Theory versus practice
A different way of thinking
What Functional Programming is not
Why use Functional Programming?
What we need
What we get
Not all is gold...
Is JavaScript functional?
JavaScript as a tool
Going functional with JavaScript
Key features of JavaScript
Functions as First Class Objects
Recursion
Closures
Arrow functions
Spread
How do we work with JavaScript?
Using transpilers
Working online
Testing
Summary
Thinking Functionally - A First Example
The problem - do something only once
Some bad solutions
Solution #1 - hope for the best!
Solution #2 - use a global flag
Solution #3 - remove the handler
Solution #4 - change the handle
Solution #5 - disable the button
Solution #6 - redefine the handler
Solution #7- use a local flag
A functional solution
A higher-order solution
Testing the solution manually
Testing the solution automatically
An even better solution
Starting Out with Functions - A Core Concept
All about functions
Of lambdas and functions
Arrow functions - the modern way
Returning values
Handling the this value
Working with arguments
One argument or many?
Functions as objects
A React+Redux reducer
An unnecessary mistake
Working with methods
Using functions in FP ways
Injection - sorting it out
Callbacks promises and continuations
Continuation Passing Style
Polyfills
Detecting Ajax
Adding missing functions
Stubbing
Immediate invocation
Behaving Properly - Pure Functions
Pure functions
Referential Transparency
Side effects
Usual side effects
Global state
Inner state
Argument mutation
Troublesome functions
Advantages of pure functions
Order of execution
Memoization
Self-documentation
Impure functions
Avoiding impure functions
Avoiding the usage of state