Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: [美] Kyle Simpson

Rating No ratings yet

JavaScript语言有很多复杂的概念,但却用简单的方式体现出来(比如回调函数),因此,JavaScript开发者无需理解语言内部的原理,就能编写出功能全面的程序。然而,JavaScript的这些复杂精妙的概念才是语言的精髓,即使是经验丰富的JavaScript开发者,如果没有认真学习,也无法真正理解语言本身的特性。正是因为绝大多数人不求甚解,一遇到出乎意料的行为就认为是语言本身有缺陷,进而把相关的特性加入黑名单,久而久之就排除了这门语言的多样性,人为地使它变得不完整、不安全。 “你不知道的JavaScript”系列就是要让不求甚解的JavaScript开发者迎难而上,深入语言内部,弄清楚JavaScript每一个零部件的用途,轻松理解前端圈里出现的各种技术、框架和流行术语。本书介绍了该系统的两个主题:“起步上路”以及“ES6及更新版本”。

AI Reading Assistant

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

AI guide
# You Don't Know JS: Up & Going / ES6 & Beyond (Chinese Edition) ## 【One-Line Pitch】 A two-part deep dive that first rebuilds your JavaScript fundamentals from scratch—types, scope, closures, and the "why" behind the language's quirks—then walks you through the most important ES6 features with practical, opinionated guidance. Ideal for developers who've written JS for years but never stopped to understand how it actually works. ## 【Book Arc】 - **Opening (~0%–13%)**: The book opens with a manifesto against "good enough" JavaScript learning, arguing that developers who avoid understanding the language's complex parts end up fearing and misusing them. It then transitions into the first major section, "Up & Going," which starts with absolute basics—values, types, and variables—as a foundation for everything that follows. - **Early (~13%–29%)**: This stage covers core programming mechanics: blocks, conditionals, loops, functions, and scope. The key insight here is that **scope is lexical**—each function creates its own variable container, and nested functions can access outer scopes. The section also introduces the seven built-in types and the infamous `typeof null === "object"` bug, which the author argues will never be fixed because too much web code depends on it. - **Early (~29%–32%)**: A bridge section on closures, IIFEs, and the "old vs. new" problem. Closures are framed as "memory"—a function that remembers its outer scope even after that scope has finished running. The book then introduces polyfilling and transpiling as the two strategies for using modern features in old browsers, setting up the ES6 material that follows. - **Middle (~32%–48%)**: The ES6 & Beyond section begins with the philosophy of "feature-based" thinking instead of version-based thinking, then dives into syntax: block-scoped `let` declarations (with a warning about the "mental tax" of implicit scoping), default parameter values, destructuring (including the subtle difference between destructuring defaults and parameter defaults), and concise methods. The author is refreshingly opinionated—he argues arrow functions' readability benefits shrink as function length grows. - **Late (~48%–end)**: The book continues through iterators, generators, modules, classes, and collections (Map, WeakMap, Set). The excerpts show a strong emphasis on **custom iterators** and the `for..of` loop, with the note that plain objects are intentionally not iterable by default—a design decision, not a bug. The book closes by positioning itself as the entry point to the broader "You Don't Know JS" series. ## 【Key Takeaways】 - **Implicit coercion is learnable, not a flaw** (Early): The book pushes back on the common belief that JavaScript's type coercion is a design defect. Once you learn the rules—like `"99.99" == 99.99` converting the string to a number—you can write better programs instead of avoiding the feature entirely. - **Only values have types, not variables** (Early): `typeof a` asks "what type is the value currently in `a`?", not "what type is `a`?". This distinction matters because a variable can hold a string, number, and object over its lifetime, and `typeof` reflects only the current value. - **Scope is lexical and nestable** (Early): Each function creates its own scope, and inner scopes can access outer ones—like balloons inside balloons. This is the foundation for understanding closures, which the book calls "one of the most important techniques in your JS toolkit." - **Closures are memory** (Early): A function returned from another function "remembers" the outer function's variables even after the outer function has finished. The `makeAdder` example shows how each call creates a new "memory" of the `x` parameter. - **Polyfilling and transpiling bridge old and new** (Early): Instead of waiting years for old browsers to die, you can write ES6 today. Polyfills replicate new features in old environments (like `Number.isNaN`), while transpilers convert ES6 syntax to ES5-equivalent code. - **`let` is block-scoped but implicit** (Middle): Unlike `var`, which belongs to the whole function, `let` belongs to its block—but this is invisible in the syntax. The author coins "mental tax" for the confusion this causes, and warns that accessing a `let` variable before its declaration throws an error, unlike `var`. - **Destructuring defaults ≠ parameter defaults** (Middle): A subtle but critical distinction. `function f6({x = 10} = {}, {y} = {y: 10})` behaves differently from what you'd expect: calling `f6({}, {})` gives `10 undefined` because the second parameter's default only applies when the argument is missing or `undefined`, not when it's an empty object. - **Arrow functions are about `this`, not just syntax** (Middle): The main design goal of `=>` is to change `this` binding behavior, not to save keystrokes. The author advises using them only for short inline functions, since readability gains shrink as function length grows. ## 【Reading Tips】 - **Skim the first 13% if you're experienced**: The opening "Up & Going" section covers basics like variables, blocks, and conditionals. If you've written JS for more than a year, jump ahead to the scope and closure material around the 20–30% mark, where the book gets distinctive. - **Deep-read the ES6 syntax chapters (30–50%)**: The destructuring, default parameters, and concise method sections contain subtle gotchas that will trip you up in real code. Pay special attention to the `f6({}, {})` example—it's the kind of edge case that causes production bugs. - **Treat the arrow function section as a debate, not a tutorial**: The author argues against overusing `=>` and makes a case for readability over brevity. Even if you disagree, this is valuable perspective for code review discussions. - **Use the "old vs. new" chapter as a mental model**: The polyfill/transpile discussion (around 29%) is short but essential for understanding how to adopt ES6 features without breaking older browsers. It also explains why the ecosystem moved to feature-based thinking instead of version-based. - **Don't expect deep coverage of generators and classes**: The excerpts show these topics exist (iterators, generators, modules, classes, Map/WeakMap/Set), but the sample material doesn't include their full treatment. If these are your primary interest, you may need supplementary resources. ## 【Coverage Limits】 The excerpts cover the "Up & Going" fundamentals and the early-to-middle portions of the ES6 & Beyond section (syntax, destructuring, arrow functions, iterators). The guide does not cover the book's later chapters on generators, modules, classes, and collections in depth, nor the final "ES6 & Beyond" summary material. ##
Page 11
............................................................147 3.2.4 错误处理 .....................................................................................
View in text
Excerpt 2
ola、Don Jones、Chris Hartjes、Alex Howes、john gibbon、David J. Groom、BBox、Yu Dilys Sun、Nate Steiner、 Brandon Satrom、Brian Wyant、Wesley Hales、 Ian Pouncey、Timoth...
View in text
Excerpt 3
参见《你不知道的 JavaScript(上卷)》第一部分。 变量的作用域到底是如何在 JavaScript 中工作的?这可能是你需要快速理解的一个最基础 的事情了。对作用域只有道听途说、模糊不清的理解是不够的。 “作用域和闭包”这部分从批判 JavaScript 是“解释性语言”因而无法编译这一常见误解开 始。事...
View in text
Excerpt 4
里的 __proto__ 属性名也可以是字符串 "__proto__",但是注意它不能是计算属性名结果(参见前一节)。 退一步讲,对 __proto__ 的使用是有争议的。它是 JavaScript 多年前的属性扩展,最后被 ES6 标准化,但似乎标准化得不情不愿。许多开发者认为不应该使用它。实际上,它是在 ES...
View in text
Excerpt 5
严格说,或 者根本不出现!)。 你甚至可以把 yield 放在循环中,用来表示一个重复暂停点。实际上,一个永不结束的循 环就意味着一个永不结束的生成器,这是完全有效的,有时候完全就是你所需要的。 yield 不只是一个暂停点。它是一个表达式,在暂停生成器的时候发出一个值。这里是一 个生成器中的 while..tr...
View in text
Excerpt 6
//some.url.1" ) .then( function fulfilled(contents){ // 处理contents成功情况 function rejected(reason){ // 处理ajax出错原因 } Promise 有一个 then(..) 方法,接受一个或两个回调函数作为参数。前面的...
View in text
Excerpt 7
ript 行为更多的控制。 接下来我们会简单介绍一下每个符号和它们的作用。 7.3.1 Symbol.iterator 在第 2 章和第 3 章中,我们介绍并使用了符号 @@iterator,它是由 ... 展开和 for..of 循 环自动使用的。在第 5 章中,我们还看到了 ES6 新特性集合中的 @@ite...
View in text
Excerpt 8
成千上万的时候。 现在我们不再只把递归作为解决问题的理论方案了,而是可以实际将其用在 JavaScript 程 序中! 对于 ES6 来说,不管是否为递归,所有的 PTC 都应该以这种方式优化。 7.7.1 尾调用重写 但这里的问题是只有 PTC 可以被优化;非 PTC 当然仍然可以工作,但会像以前一样触发 栈帧...
View in text
Tags
AI categories
JavaScriptProgramming LanguageProgramming
Publish Year: 2018
Language: English
Pages: 264
File Format: PDF
File Size: 8.3 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…