Book description
How often do you hear people say things like this? "Our JavaScript is a mess, but we’re thinking about using [framework of the month]."
Like it or not, JavaScript is not going away. No matter what framework or ”compiles-to-js” language or library you use, bugs and performance concerns will always be an issue if the underlying quality of your JavaScript is poor. Rewrites, including porting to the framework of the month, are terribly expensive and unpredictable. The bugs won’t magically go away, and can happily reproduce themselves in a new context. To complicate things further, features will get dropped, at least temporarily.
The other popular method of fixing your JS is playing “JavaScript Jenga,” where each developer slowly and carefully takes their best guess at how the out-of-control system can be altered to allow for new features, hoping that this doesn’t bring the whole stack of blocks down. This book provides clear guidance on how best to avoid these pathological approaches to writing JavaScript:
- Recognize you have a problem with your JavaScript quality.
- Forgive the code you have now, and the developers who made it.
- Learn repeatable, memorable, and time-saving refactoring techniques.
- Apply these techniques as you work, fixing things along the way.
- Internalize these techniques, and avoid writing as much problematic code to begin with.
Bad code doesn’t have to stay that way. And making it better doesn’t have to be intimidating or unreasonably expensive.
Publisher resources
Table of contents
- Foreword
- Preface
- 1. What Is Refactoring?
- 2. Which JavaScript Are You Using?
- 3. Testing
- 4. Testing in Action
- 5. Basic Refactoring Goals
- 6. Refactoring Simple Structures
-
7. Refactoring Functions and Objects
- The Code (Improved)
- Array and Object Alternatives
- Testing What We Have
- Extracting Functions
-
Streamlining the API with One Global Object
- Extracting the classifier Object
- Inlining the setup Function
- Extracting the songList Object
- Handling the Remaining Global Variables
- Making Data Independent from the Program
- Scoping Declarations: var, let, and const
- Bringing classify into the classifier
- Untangling Coupled Values
- Objects with Duplicate Information
- Bringing the Other Functions and Variables into classifier
- Shorthand Syntax: Arrow, Object Function, and Object
- Getting New Objects with Constructor Functions
- Constructor Functions Versus Factory Functions
- A class for Our Classifier
- Choosing Our API
- Time for a Little Privacy?
- Adapting the Classifier to a New Problem Domain
- Wrapping Up
- 8. Refactoring Within a Hierarchy
- 9. Refactoring to OOP Patterns
- 10. Asynchronous Refactoring
- 11. Functional Refactoring
- 12. Conclusion
- A. Further Reading and Resources
- Index
Product information
- Title: Refactoring JavaScript
- Author(s):
- Release date: March 2017
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491964873
You might also like
book
Clean Code in JavaScript
Get the most out of JavaScript for building web applications through a series of patterns, techniques, …
book
Rediscovering JavaScript
JavaScript is no longer to be feared or loathed - the world's most popular and ubiquitous …
book
Simplifying JavaScript
The best modern JavaScript is simple, readable, and predictable. Learn to write modern JavaScript not by …
book
Refactoring TypeScript
Discover various techniques to develop maintainable code and keep it in shape. Key Features Learn all …