20200225
Plan
- 你不知道的 js
- css 权威指南
Notes
- 空 Array
b = [];
b.length = 3;
c = b.map((i, index) => {
// 不会进入循环
return index;
}); // [empty * 3]
类数组
- dom 查询的返回
- arguments
- ...
字符串可以借用数组的方法。前提:这个数组方法不改变数组本身,而是返回新对象。
a = "123";
b = Array.prototype.join.call(a, "-");
c = Array.prototype.map.call(a, i => i.toUpperCase);
- 数字
// 数字后面紧跟的第一个点会被认为是数字的一部分
42.toFixed(3); // error;
42..toFixed(3); // 42.000;
(42).toFixed(3); // 42.000;
0.42.toFixed(3); // 0.420;
42 .toFixed(3); // 42.000;
"abc".toUpperCase(); // ABC;
- 机器精度(machine epsilone)
Number.EPSILON; // 2^-52
精度丢失
双浮点的溢出
安全的整数: 安全的整数就是在 -(2^53 - 1) ~ (2^53 - 1)之间的数字
位运算符只适用于 32 位整数
NaN
typeof NaN; // "number"
NaN === NaN; // false
Object.is(NaN, NaN); // true
- +0 vs -0
Object.is(+0, -0); // false
+0 === -0; // true
// 判断-0
number === 0 && 1 / number === -Infinity;
- 除了 @media 还有@support
/* 如果支持 color 属性,就应用 */
@support (color: black) {
color: red;
}