Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Luis Atencio

Rating No ratings yet

Whether building interactive browser-based applications or creating server-side applications in Node, JavaScript is the most widely used language for web programming. With new features, language improvements, paradigms, and potential use cases appearing regularly, there’s never been a more exciting time to be a JavaScript developer. In The Joy of JavaScript, author and JavaScript expert Luis Atencio teaches you key design concepts that lead to clean, lean, modular, and easy-to-maintain code. About the Technology JavaScript is at the heart of web applications on the browser side and, via the popular Node.js runtime, it often powers the server side too. Simply put, the web runs on JavaScript. About the book The Joy of JavaScript introduces techniques that turn JavaScript programmers into JavaScript pros. You’ll work with cutting edge APIs, language features, and coding styles to tackle tricky problems in an elegant manner. Along the way, you’ll practice good object design, drive business logic with functional thinking, and untangle complex data flows. What's inside • JavaScript’s objects and module system • Working with higher order functions • Identifying and creating composable software • Preparing for upcoming JavaScript features About the reader Written for experienced and passionate JavaScript developers. About the author Luis Atencio is a software engineer for Citrix Systems, author of Manning’s Functional Programming in JavaScript, and co-author of Manning’s RxJS in Action.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical guide for experienced JavaScript developers to master object modeling, functional programming, and asynchronous data flows, turning everyday coding into elegant, composable, and maintainable software. 【Book Arc】 - **Opening (~0%–9%)**: Introduces the book's four-part journey—objects, functions, modularity, and streams—and sets the stage with a sample blockchain application. It frames JavaScript's unique strengths (prototype-based objects, higher-order functions) and the promise of declarative, functional code. - **Early (~9%–28%)**: Dives into inheritance-based object modeling, contrasting prototype chains with class syntax. Covers property descriptors (enumerable, configurable, writable), constructor functions, and modern class features like private and static fields, using a Transaction example. - **Middle (~28%–47%)**: Explores linked and compositional object models, introducing OLOO (objects linking to other objects) and mixins via `Object.assign`. Addresses the fragile base class problem and the diamond problem of multiple inheritance, showing how concatenative extension offers flexibility. - **Late (~47%–60%)**: Discusses trade-offs of mixins (memory footprint, prototype pollution) and transitions toward functional programming. Emphasizes decomposition and composition, pure functions, and higher-order functions as tools for cleaner, more declarative code. - **Ending (~60%–100%)**: Covers separation of concerns through modules and metaprogramming, then tackles asynchronous programming with promises, async/await, and observables/streams. Concludes with a unidirectional data pipeline approach for handling complex data flows. 【Key Takeaways】 - **Prototypes are dynamic, not static blueprints** (Early): JavaScript's prototype chain allows runtime manipulation, unlike class-based languages. Understanding `Object.create` and property descriptors gives fine control over object behavior, enabling more flexible and predictable code. - **Classes are syntactic sugar over prototypes** (Early): The `class` and `extends` keywords simplify prototype setup, but the underlying mechanism remains delegation. Private fields (`#feePercent`) and static methods (`#precisionRound`) showcase modern syntax for cleaner encapsulation. - **Mixins solve multiple inheritance without the diamond problem** (Middle): Using `Object.assign` to concatenate properties from multiple objects avoids the ambiguity of class-based multiple inheritance. This pattern is used in real-world libraries like Chai and browser APIs like `WindowOrWorkerGlobalScope`. - **Composition over inheritance reduces fragility** (Middle): The fragile base class problem—where changes to base objects ripple downstream—is mitigated by copying state via mixins rather than relying on rigid hierarchies. This makes models more resilient to change. - **Functional programming complements JavaScript's design** (Early–Middle): Higher-order functions, pure functions, and immutability prevent bugs and make code more declarative. Decomposition (breaking problems into small pieces) and composition (reassembling them) are core to this mindset. - **Separation of concerns is achievable via modules and metaprogramming** (Late): Static modularity organizes code, while dynamic metaprogramming (e.g., extending objects at runtime) offers flexibility. Both are essential for maintainable, scalable applications. - **Asynchronous flows are unified through streams and observables** (Late): Promises and async/await abstract async nature, but observables provide a consistent interface over any data source—sync, async, single-value, or infinite. This enables unidirectional data pipelines for complex flows. 【Reading Tips】 - **Skim the blockchain example early** (Opening–Early): It's a recurring case study, but don't get bogged down in details initially. Focus on how it illustrates object modeling and later functional and async concepts. - **Deep-read the object modeling chapters** (Early–Middle): Chapters 2–3 are dense but foundational. Pay special attention to property descriptors and `Object.assign`—they're crucial for understanding mixins and later metaprogramming. - **Practice with code listings** (Throughout): The book is code-heavy. Type out and run examples, especially the Transaction and HashTransaction classes, to internalize prototype chains and class syntax. - **Watch for trade-off discussions** (Middle–Late): The author is candid about performance costs (e.g., mixin memory footprint). Skim these sections for practical decision-making, but don't memorize every detail. - **Take away the functional mindset** (Late): Even if you skip some advanced FP theory, grasp the decomposition/composition workflow. It's the book's core philosophy and will improve your day-to-day coding. 【Coverage Limits】 Excerpts primarily cover the first half of the book (object modeling and early FP). Detailed content on modules, metaprogramming, and advanced async/streams is mentioned but not fully excerpted; readers should consult the full text for those sections.
Page 13
131 Kinds of ADTs 131 ■ Choices 132 ■ Modeling success and failure with the Validation monad 134 ■ Composing with monads 138 ■ Higher-kinded composition with...
View in text
Excerpt 2
r our assumptions continue to be valid in the next listing. Listing 2.3 Inspecting the new transaction objects Object.getPrototypeOf(moneyTransaction) === tr...
View in text
Excerpt 3
scuss in sections 3.2 and 3.5, respectively. 3.1.2 Explicit On the other hand, objects are linked explicitly when the link is well-known and visi- bly set in...
View in text
Excerpt 4
jects at play in our simple blockchain application. I have not shown Money, a value object that describes an amount and currency. mixins). Parting from the t...
View in text
Excerpt 5
tion, finally arriving at assembling individual functions. Now that you understand the composition pattern, let’s use it to decompose and sim- plify the hash...
View in text
Excerpt 6
cover only enough FP to open your eyes to how it’s steering JavaScript’s future, as well as helping you become proficient and do more with less. If you’d lik...
View in text
Excerpt 7
application. Abide by them, and any third-party code or any other parts of your application that implement or support these types know exactly how to work wi...
View in text
Excerpt 8
cripts ran within the same global browser realm. (I’ll dis- cuss realms briefly in chapter 7.) Without property encapsulation, a global variable, a class, or...
View in text
Tags
AI categories
Programming LanguageJavaScriptBackend
ISBN: 1617295868
Publish Year: 2021
Language: English
Pages: 360
File Format: PDF
File Size: 6.5 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…