es6
山海一哥
为者常成,行者常至
展开
-
数组去重和字符串去重的方法
// 去除数组的重复成员[...new Set(array)]上面的方法也可以用于,去除字符串里面的重复字符。[...new Set('ababbc')].join('')// "abc"原创 2019-01-30 14:00:59 · 294 阅读 · 0 评论 -
object新增super属性
我们知道,this关键字总是指向函数所在的当前对象,ES6 又新增了另一个类似的关键字super,指向当前对象的原型对象。const proto = { foo: 'hello'};const obj = { foo: 'world', find() { return super.foo; }};Object.setPrototypeOf(obj, proto...转载 2019-01-30 14:05:10 · 434 阅读 · 0 评论 -
求数组的合集,交集,差集
使用 Set 可以很容易地实现并集(Union)、交集(Intersect)和差集let a = new Set([1, 2, 3]);let b = new Set([4, 3, 2]);// 并集let union = new Set([...a, ...b]);// Set {1, 2, 3, 4}// 交集let intersect = new Set([...a].fi...转载 2019-01-30 14:36:43 · 1824 阅读 · 2 评论 -
Array.from和Array.of
Array.from方法用于将两类对象转为真正的数组:类似数组的对象(array-like object)和可遍历(iterable)的对象(包括 ES6 新增的数据结构 Set 和 Map)et arrayLike = { '0': 'a', '1': 'b', '2': 'c', length: 3};// ES5的写法var arr1 = [].sl...转载 2019-01-30 14:52:10 · 1028 阅读 · 0 评论