Capítulo 839 de 859

Chapter 839: Prerequisites (Manual)

Core Idea

The manual assumes solid working knowledge of modern JavaScript/DOM/ES6+ (modules, closures, this, destructuring, classes, promises/async-await, template literals) — this lesson is a quick refresher list of that expected background, not a JS tutorial itself.

Key Concepts

  • ES6 modules: loading three.js via import inside <script type="module"> and import maps, rather than global <script> tags.
  • this binding: not magic — it's effectively an implicit argument; calling a function via the dot operator (obj.fn()) sets this to obj, while passing a bare function reference as a callback (e.g. to a loader) loses that binding unless explicitly bound or wrapped in an arrow function.
  • Closures: a function defined inside another function retains access to (closes over) the outer function's variables — commonly relied on for callback state in three.js examples.
  • Modern syntax expected throughout the manual: const/let instead of var, for...of instead of for...in, array forEach/map/filter, object/array destructuring, the rest/spread operators, class syntax with getters/setters, arrow functions (which bind this lexically), promises and async/await, and template literals.
  • Recommended tooling: an editor with linting (e.g. VS Code + ESLint with no-undef) catches undefined-variable typos early; when using global <script> tags instead of modules, add /* global THREE */ so the linter doesn't flag the global.

Key Takeaways

  1. The manual assumes comfort with ES6+ JavaScript (modules, destructuring, classes, promises/async-await) and basic DOM/CSS-selector knowledge — it will not re-teach these.
  2. A common beginner trap is passing a method as a bare callback and being surprised this is no longer bound — use an arrow function or explicit .bind() when that matters.
  3. Prefer const/let over var, and for...of over for...in, matching the conventions used throughout the manual's own code samples.
  4. Editor linting (ESLint's no-undef rule in particular) catches a lot of the typo-class bugs beginners hit early in a three.js project.

Connects To

  • Fundamentals (manual): the first substantive lesson this prerequisites page is meant to prepare you for.