{flat,flatMap}
flat
Array.prototype.flat( [ depth ] )
即用来打平数组的flatten方法,支持一个可选的depth参数,表示打平指定层数(默认为...flated : flat(flated, depth - 1);
}
return arr;
};
flatMap
Array.prototype.flatMap ( mapperFunction...[ , thisArg ] )
P.S.可选参数thisArg用作mapperFunction中的this,例如:
[1, 2, 3, 4].flatMap(function(x) {
return...(也可以对应 0 个)
例如:
[2, 0, 1, 9].flatMap(x => new Array(x).fill(x))
// 得到 [2, 2, 1, 9, 9, 9, 9, 9, 9, 9,...)
浏览器特性检测:只想知道是否支持特定特性
善后措施异常:比如logError()自身出现异常,即便能捕获到也无计可施了
P.S.即便在这些场景,决定忽略一个异常时也应该在注释中说明原因
Array.prototype.sort