背景图片

JavaScript 权威指南(犀牛书) 第 8 章:函数

8.1 定义函数 Defining Functions

8.1.1 函数声明 Function Declarations

// Compute the distance between Cartesian points (x1,y1) and (x2,y2).
function distance(x1, y1, x2, y2) {
let dx = x2 - x1;
let dy = y2 - y1;
return Math.sqrt(dx*dx + dy*dy);
}

8.1.2 函数表达式 Function Expressions

8.1.3 箭头函数 Arrow Functions

8.1.4 嵌套函数 Nested Functions

8.2 调用函数 Invoking Functions

8.2.1 函数调用 Function Invocation

8.2.2 方法调用 Method Invocation

8.2.3 构造函数调用 Constructor Invocation

8.2.4 间接调用 Indirect Invocation

8.2.5 隐式函数调用 Implicit Function Invocation


8.3 函数实参与形参 Function Arguments and Parameters

8.3.1 可选形参与默认值 Optional Parameters and Defaults

8.3.2 剩余形参与可变长度实参列表 Rest Parameters and Variable-Length Argument Lists

8.3.3 Arguments 对象 Rest Parameters and Variable-Length Argument Lists

8.3.4 在函数调用中使用扩展操作符 The Spread Operator for Function Calls

8.3.5 把函数实参解构为形参 Destructuring Function Arguments into Parameters

8.3.6 参数类型 Argument Types

8.4 函数作为值 Functions as Values

8.4.1 定义自己的函数属性 Defining Your Own Function Properties

8.5 函数作为命名空间 Functions as Namespaces

8.6 闭包 Closures

8.7 函数属性、方法与构造函数 Function Properties, Methods, and Constructor

8.8 函数式编程 Functional Programming

8.9 小结 Summary