阮一峰 《ECMAScript 6入门》 第三版
上面的表达式虽然毫无意义,但是语法是合法的,可以执行。 对象的解构赋值,可以很方便地将现有对象的方法,赋值到某个变量。 变量的解构赋值 54 let { log, sin, cos } = Math; 上面代码将 Math 对象的对数、正弦、余弦三个方法,赋值到对应的变量上,使用 起来就会方便很多。 由于数组本质是特殊的对象,因此可以对数组进行对象属性的解构。 let arr = [1, 2, 3]; // false ES5 可以通过下面的代码,部署 Number.isInteger() 。 数值的扩展 111 (function (global) { var floor = Math.floor, isFinite = global.isFinite; Object.defineProperty(Number, 'isInteger', { value: // true 因此, Number.EPSILON 的实质是一个可以接受的误差范围。 function withinErrorMargin (left, right) { return Math.abs(left - right) < Number.EPSILON; } withinErrorMargin(0.1 + 0.2, 0.3) // true withinErrorMargin(00 码力 | 679 页 | 2.66 MB | 1 年前3阮一峰 JavaScript 教程
Object 对象 属性描述对象 Array 对象 包装对象 Boolean 对象 - 1 - 本文档使用 书栈(BookStack.CN) 构建 Number 对象 String 对象 Math 对象 Date 对象 RegExp 对象 JSON 对象 面向对象编程 实例对象与 new 命令 this 关键字 对象的继承 Object 对象的相关方法 严格模式 异步操作 JavaScript 的核心语法部分相当精简,只包括两个部分:基本的语 法构造(比如操作符、控制结构、语句)和标准库(就是一系列具有各 种功能的对象比如 Array 、 Date 、 Math 等)。除此之外,各种宿 主环境提供额外的 API(即只能在该环境使用的接口),以便 JavaScript 调用。以浏览器为例,它提供的额外 API 可以分成三 大类。 浏览器控制类:操作浏览器 的整数,即-253到253,都可以精确表示。 1. Math.pow(2, 53) 2. // 9007199254740992 3. 4. Math.pow(2, 53) + 1 5. // 9007199254740992 6. 7. Math.pow(2, 53) + 2 8. // 9007199254740994 9. 10. Math.pow(2, 53) + 3 11.0 码力 | 540 页 | 3.32 MB | 10 月前3Debian 维护者指南
files 此处的源码如下所示。 src/hello.c(v=1.4): $ cat debhello-1.4/src/hello.c #include "config.h" #include <math.h> #includeint main() { printf("Hello, I am " PACKAGE_AUTHOR "!\n"); printf("4.0 * atan(1 gz。 此类型的源码旨在作为非系统文件安装,例如: $ tar -xzmf debhello-1.5.tar.gz $ cd debhello-1.5 $ ./configure --with-math $ make $ make install 让我们取得源码并制作 Debian 软件包。 下载 debhello-1.5.tar.gz $ wget http://www.example.o 5/src/hello.c #include "config.h" #ifdef WITH_MATH # include <math.h> #endif #include int main() { printf("Hello, I am " PACKAGE_AUTHOR "!\n"); #ifdef WITH_MATH printf("4.0 * atan(1.0) = %10f8\n", 0 码力 | 142 页 | 1.11 MB | 1 年前3Ubuntu 桌面培训 2010
. . . . . . . . . . . . . . . . . . . . . . . . . 118 目录 5 Ubuntu 桌面培训 目录 4.1.6 OpenOffice.org Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 4.2 使用 OpenOffice.org 文字处理 . . . . . . . . . . . . . . 188 4.6 使用 OpenOffice.org Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 4.6.1 OpenOffice.org Math 的主要特性 . . . . . . . . . . . . . . . . . . . 201 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 4.90 运行 Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0 码力 | 524 页 | 57.54 MB | 1 年前3TypeScript Handbook(中文版)
state.enthusiasmLevel + 1 case DECREMENT_ENTHUSIASM: return { ...state, enthusiasmLevel: Math.max(1, state.enthusiasmLevel - } return state; } 注意我们使用了对象展开( ...state ),当替换 enthusiasmLevel getDistance(p: Point) { let dx = p.x - this.x; let dy = p.y - this.y; return Math.sqrt(dx ** 2 + dy ** 2); } } // ... // Reopen the interface. interface Point { dist size * s.size; case "rectangle": return s.width * s.height; case "circle": return Math.PI * s.radius * s.radius; } } function test1(s: Shape) { if (s.kind === "square") {0 码力 | 557 页 | 7.48 MB | 1 年前3Hello 算法 1.0.0b5 TypeScript 版
0; i < n; i++) { nums[i] = i + 1; } // 随机打乱数组元素 for (let i = 0; i < n; i++) { const r = Math.floor(Math.random() * (i + 1)); const temp = nums[i]; nums[i] = nums[r]; nums[r] = temp; } return nums; randomAccess(nums: number[]): number { // 在区间 [0, nums.length) 中随机抽取一个数字 const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 const random_num = nums[random_index]; return random_num; height; } /* 更新节点高度 */ updateHeight(node: TreeNode): void { // 节点高度等于最高子树高度 + 1 node.height = Math.max(this.height(node.left), this.height(node.right)) + 1; } 2. 节点平衡因子 节点的「平衡因子 balance factor」0 码力 | 378 页 | 30.70 MB | 1 年前3Hello 算法 1.1.0 TypeScript版
0; i < n; i++) { nums[i] = i + 1; } // 随机打乱数组元素 for (let i = 0; i < n; i++) { const r = Math.floor(Math.random() * (i + 1)); const temp = nums[i]; 第 2 章 复杂度分析 hello‑algo.com 41 nums[i] = nums[r]; randomAccess(nums: number[]): number { // 在区间 [0, nums.length) 中随机抽取一个数字 const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 const random_num = nums[random_index]; return random_num; number): number { return 2 * i + 2; } /* 获取索引为 i 节点的父节点的索引 */ parent(i: number): number { return Math.floor((i - 1) / 2); // 向下整除 } /* 层序遍历 */ levelOrder(): number[] { let res = []; // 直接遍历数组 for0 码力 | 383 页 | 18.49 MB | 1 年前3Hello 算法 1.0.0b5 JavaScript版
0; i < n; i++) { nums[i] = i + 1; } // 随机打乱数组元素 for (let i = 0; i < n; i++) { const r = Math.floor(Math.random() * (i + 1)); const temp = nums[i]; nums[i] = nums[r]; nums[r] = temp; } return nums; 随机访问元素 */ function randomAccess(nums) { // 在区间 [0, nums.length) 中随机抽取一个数字 const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 const random_num = nums[random_index]; return random_num; null ? -1 : node.height; } /* 更新节点高度 */ #updateHeight(node) { // 节点高度等于最高子树高度 + 1 node.height = Math.max(this.height(node.left), this.height(node.right)) + 1; } 2. 节点平衡因子 节点的「平衡因子 balance factor」0 码力 | 375 页 | 30.68 MB | 1 年前3Hello 算法 1.1.0 JavaScript版
0; i < n; i++) { nums[i] = i + 1; } // 随机打乱数组元素 for (let i = 0; i < n; i++) { const r = Math.floor(Math.random() * (i + 1)); const temp = nums[i]; 第 2 章 复杂度分析 hello‑algo.com 41 nums[i] = nums[r]; 随机访问元素 */ function randomAccess(nums) { // 在区间 [0, nums.length) 中随机抽取一个数字 const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 const random_num = nums[random_index]; return random_num; hello‑algo.com 149 right(i) { return 2 * i + 2; } /* 获取索引为 i 节点的父节点的索引 */ parent(i) { return Math.floor((i - 1) / 2); // 向下整除 } /* 层序遍历 */ levelOrder() { let res = []; // 直接遍历数组 for (let i =0 码力 | 379 页 | 18.46 MB | 1 年前3Hello 算法 1.2.0 简体中文 JavaScript 版
0; i < n; i++) { nums[i] = i + 1; } // 随机打乱数组元素 for (let i = 0; i < n; i++) { const r = Math.floor(Math.random() * (i + 1)); const temp = nums[i]; 第 2 章 复杂度分析 www.hello‑algo.com 41 nums[i] = nums[r]; 随机访问元素 */ function randomAccess(nums) { // 在区间 [0, nums.length) 中随机抽取一个数字 const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 const random_num = nums[random_index]; return random_num; hello‑algo.com 149 right(i) { return 2 * i + 2; } /* 获取索引为 i 节点的父节点的索引 */ parent(i) { return Math.floor((i - 1) / 2); // 向下整除 } /* 层序遍历 */ levelOrder() { let res = []; // 直接遍历数组 for (let i =0 码力 | 379 页 | 18.47 MB | 9 月前3
共 218 条
- 1
- 2
- 3
- 4
- 5
- 6
- 22