MindMap Gallery JavaScript函数与作用域导图
Explore the fascinating world of JavaScript functions and scope with our comprehensive guide! This mind map delves into the essence of functions, including their definitions, invocation patterns, and how data is passed through parameters and arguments. Understand the different ways to declare functionssuch as function declarations, expressions, arrow functions, and morewhile discovering their unique behaviors like hoisting and this-binding. Learn about various invocation patterns, including method calls and higher-order functions. Additionally, grasp how parameters and arguments work, from default and rest parameters to destructuring and handling mismatched counts. This structured overview equips you with essential knowledge for mastering JavaScript functions and their versatile applications.
Edited at 2026-03-20 03:57:25Unlock the mysteries of how neurons communicate! This overview delves into synaptic transmission, the vital process by which neurons relay information across synapses, utilizing both electrical and chemical signaling. We explore the core components of synapses, including presynaptic terminals, synaptic clefts, and postsynaptic membranes, along with the roles of supporting elements like astrocytes and microglia. Discover the mechanisms behind chemical and electrical synaptic transmission, the step-by-step process of neurotransmitter release, and the diverse outcomes of excitatory and inhibitory signaling. Learn how these intricate interactions lay the biological foundation for learning, memory, and overall brain function. Join us in understanding this essential aspect of neuronal communication!
Discover the fascinating world of acid-base theories, which provide essential frameworks for understanding chemical behavior in various contexts. This overview explores key models, including Arrhenius, Brønsted-Lowry, and Lewis theories, highlighting their definitions, typical reactions, strengths, and limitations. We delve into concepts like neutralization, pH, and solvent effects, alongside specialized theories like Lux-Flood and Usanovich, which broaden the scope of acid-base interactions. Additionally, the HSAB principle offers insights into the compatibility of acids and bases. Join us in uncovering how these theories explain and predict chemical phenomena across diverse environments.
Discover the rich tapestry of Japan's history, from its mythic origins to modern industrialization. This timeline provides a structured overview of key periods, including the early state formation marked by the legendary Emperor Jimmu and the introduction of Buddhism. Explore the classical era with the establishment of the Nara and Heian capitals, the rise of shogunate rule in Kamakura, and the fragmented authority during the Muromachi period. Witness the unification efforts of notable figures like Oda Nobunaga and Tokugawa Ieyasu leading to the Edo period's stability. Finally, delve into the pressures faced by the Tokugawa shogunate as Japan encounters the West, setting the stage for profound transformation. Join us in this journey through time!
Unlock the mysteries of how neurons communicate! This overview delves into synaptic transmission, the vital process by which neurons relay information across synapses, utilizing both electrical and chemical signaling. We explore the core components of synapses, including presynaptic terminals, synaptic clefts, and postsynaptic membranes, along with the roles of supporting elements like astrocytes and microglia. Discover the mechanisms behind chemical and electrical synaptic transmission, the step-by-step process of neurotransmitter release, and the diverse outcomes of excitatory and inhibitory signaling. Learn how these intricate interactions lay the biological foundation for learning, memory, and overall brain function. Join us in understanding this essential aspect of neuronal communication!
Discover the fascinating world of acid-base theories, which provide essential frameworks for understanding chemical behavior in various contexts. This overview explores key models, including Arrhenius, Brønsted-Lowry, and Lewis theories, highlighting their definitions, typical reactions, strengths, and limitations. We delve into concepts like neutralization, pH, and solvent effects, alongside specialized theories like Lux-Flood and Usanovich, which broaden the scope of acid-base interactions. Additionally, the HSAB principle offers insights into the compatibility of acids and bases. Join us in uncovering how these theories explain and predict chemical phenomena across diverse environments.
Discover the rich tapestry of Japan's history, from its mythic origins to modern industrialization. This timeline provides a structured overview of key periods, including the early state formation marked by the legendary Emperor Jimmu and the introduction of Buddhism. Explore the classical era with the establishment of the Nara and Heian capitals, the rise of shogunate rule in Kamakura, and the fragmented authority during the Muromachi period. Witness the unification efforts of notable figures like Oda Nobunaga and Tokugawa Ieyasu leading to the Edo period's stability. Finally, delve into the pressures faced by the Tokugawa shogunate as Japan encounters the West, setting the stage for profound transformation. Join us in this journey through time!
JavaScript Functions & Scope Mind Map
Functions Overview
What a function is
Reusable block of code that can be executed (called/invoked)
Can accept inputs (parameters) and return an output (return value)
First-class citizens
Can be assigned to variables
Can be passed as arguments to other functions
Can be returned from functions
Can be stored in arrays/objects
Function Definitions (How to Declare/Create)
Function Declaration
Syntax: function name(a, b) { ... }
Hoisting
Entire function body is hoisted (can be called before declaration)
Has a name (useful in stack traces)
Function Expression
Syntax: const fn = function(a, b) { ... };
Not hoisted like declarations (variable is hoisted, initialization is not)
Named function expression
Syntax: const fn = function named(a) { ... };
Name is scoped to the function body (useful for recursion/debugging)
Arrow Function
Syntax: const fn = (a, b) => { ... }
Expression form (not hoisted as a declaration)
Lexical this and arguments (does not bind its own)
Cannot be used as constructors (new not allowed)
Concise bodies
Expression body returns implicitly: a => a * 2
Block body requires return: a => { return a * 2; }
Method Definitions (Object/Class)
Object method shorthand
Syntax: { sum(a,b) { return a+b; } }
this depends on call-site
Class methods
Prototype methods: class C { m() {} }
Static methods: static m() {}
Constructor Function
Syntax: function Person(name){ this.name=name } + new Person("A")
new behavior
Creates a new object
Sets prototype
Binds this to the new object
Returns this unless explicit object is returned
Generator Function
Syntax: function* gen(){ yield 1; }
Returns an iterator; supports yield/yield*
Async Function
Syntax: async function f(){ return 1 }
Always returns a Promise
await pauses within async function
IIFE (Immediately Invoked Function Expression)
Syntax: (function(){ ... })();
Used to create a private scope (historically pre-let/const)
JS functions can be defined as declarations/expressions (incl. arrow), as object/class methods, and via special forms (constructor, generator, async, IIFE); hoisting and this-binding vary by form.
Function Calling (Invocation Patterns)
Basic call
fn() or fn(arg1, arg2)
Execution context is created per call
Method call
obj.method()
this is typically obj (unless extracted)
Constructor call
new Fn()
this is the newly created instance
Indirect calls with explicit this
fn.call(thisArg, a, b)
fn.apply(thisArg, [a, b])
fn.bind(thisArg, a) returns a new function (does not invoke immediately)
Optional chaining
obj.method?.() calls only if method exists
Default/short-circuit invocation patterns
cond && fn() (call only if cond truthy)
Recursion
Function calls itself directly or indirectly
Base case prevents infinite recursion
Higher-order functions
Takes functions as input or returns functions
Common examples: map, filter, reduce, event handlers
Parameters & Arguments (How Data Is Passed)
Terminology
Parameter: variable in function definition
Argument: value supplied at call site
Argument passing model
JavaScript is pass-by-sharing (call-by-sharing)
Primitives: value is copied into parameter
Objects/functions: reference to the object is copied
Mutating object inside function affects the same object
Reassigning parameter does not affect caller’s variable
Default parameters
Syntax: function f(a = 1) { ... }
Evaluated at call time
Can depend on earlier parameters: f(a, b = a*2)
Rest parameters
Syntax: function f(a, ...rest) { }
Collects remaining arguments into an array
Must be last parameter
arguments object (non-arrow functions)
Array-like object of passed arguments
Not available in arrow functions
Prefer rest parameters in modern code
Destructuring parameters
Object destructuring: function f({x, y}) { }
Array destructuring: function f([a, b]) { }
Combine with defaults: function f({x=0} = {}) { }
Parameter count mismatch
Extra arguments are allowed (accessible via rest/arguments)
Missing arguments become undefined (unless default applied)
Named vs positional arguments pattern
Positional: f(a, b, c) (order matters)
Named-like: f({a, b, c}) (object parameter for clarity)
Returning values
return value sends value to caller
No return or return; yields undefined
Returning multiple values
Use arrays/objects: return {x, y}
Scope Fundamentals (Where Variables Are Visible)
Lexical (static) scope
Determined by code structure at definition time, not call time
Inner scopes can access outer scope variables
Scope types
Global scope
Browser: window (non-module scripts)
Modules: top-level scope is module-scoped (not global)
Function scope
Created by functions (also for var)
Block scope
Created by {} blocks (for let/const), including if, for, while, try/catch
Module scope
Each ES module has its own top-level scope
Scope chain
Lookup starts in current scope, then walks outward to global
If not found
ReferenceError when accessing undeclared identifiers (in strict mode and generally)
Variable declarations and scoping rules
var
Function-scoped (or global if declared at top level in non-module scripts)
Hoisted and initialized to undefined
Can be redeclared in same scope
let
Block-scoped
Hoisted but in Temporal Dead Zone (TDZ) until initialized
Cannot be redeclared in same scope
const
Block-scoped
Must be initialized at declaration
Binding is immutable, but referenced object may be mutable
function declarations
Usually hoisted to top of scope
Block behavior in strict mode follows spec (block-scoped in many cases)
class declarations
Block-scoped
Hoisted but in TDZ
Temporal Dead Zone (TDZ)
Accessing let/const before declaration throws ReferenceError
Exists from start of block until declaration is evaluated
Closures (Functions Remember Their Lexical Environment)
Definition
A function plus access to the variables in its outer lexical scopes
How closures are created
Inner function defined inside outer function captures variables
Captured variables live as long as closure is reachable
Common uses
Data privacy / encapsulation
Private state via captured variables
Function factories
Returning specialized functions
Memoization/caching
Event handlers and callbacks
Common pitfalls
Capturing loop variables
With var in loops: all closures share same binding
Fixes
Use let in loop header (new binding per iteration)
Create IIFE per iteration
this and Scope (Related but Different Concepts)
Key distinction
Scope is lexical; this is runtime-binding (call-site dependent)
this binding rules (common cases)
Function call: fn() → this is undefined in strict mode, global object in sloppy mode
Method call: obj.fn() → this is obj
Constructor: new Fn() → this is new instance
Explicit: call/apply/bind sets this
Arrow functions
Do not have their own this; they capture this from surrounding scope
Losing this
Extracting method: const m = obj.method; m() loses obj
Fixes
bind(obj)
Wrapper: () => obj.method()
Hoisting & Execution Model (Why Declarations Behave Differently)
Creation phase vs execution phase (conceptual)
Declarations registered before code runs
Hoisting summary
function declarations: hoisted with implementation
var: hoisted and set to undefined
let/const/class: hoisted but inaccessible due to TDZ
Strict mode impact
Prevents accidental globals
Changes default this in plain calls to undefined
Best Practices (Functions + Scope)
Prefer const and let over var
Use arrow functions for callbacks where lexical this is desired
Use function declarations for APIs you want hoisted/readable
Prefer rest parameters over arguments
Prefer object parameters for many optional arguments
Avoid relying on outer mutable state; pass dependencies explicitly
Minimize global variables; use modules
Be careful with closures in loops and async callbacks
Name functions for clearer stack traces and debugging