
ES6
文章平均质量分 89
南风知我意,吹梦到西洲。
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
超详细的 JS 数组方法整理
数组是 js 中最常用到的数据集合,其内置的方法有很多,熟练掌握这些方法,可以有效的提高我们的工作效率,同时对我们的代码质量也是有很大影响。一、创建数组1.使用数组字面量表示法var arr4 = []; //创建一个空数组var arr5 = [20]; // 创建一个包含1项数据为20的数组var arr6 = ["lily","lucy","Tom"]; // 创建一个包含3个字符串的数组2.使用 Array 构造函数无参构造var arr1 = new Array();转载 2021-01-26 12:42:01 · 267 阅读 · 0 评论 -
ECMAScript 6 的Map映射
映射(Map)是 ECMAScript 6 规范中引入的一种数据结构。这是一种存储键值对列表很方便的方法,类似于其他编程语言中的词典或者哈希表。什么是映射JavaScript 的对象(Object),本质上是键值对的集合(Hash结构),但是传统上只能用字符串当作键,这给使用带来了很大的限制。为了解决这个问题,ECMAScript 6 引入了 Map 数据结构。它类似于对象,也是键值对的集合,但是"键"的范围不仅仅局限于字符串,而是各种类型的值(包括对象)都可以当作键。也就是说,Object 结构(转载 2021-01-25 14:08:30 · 253 阅读 · 0 评论 -
字符串填充
console.log('a'.padStart(4,'XXX'))1.向前填充let str='apple';let pasStr='xxx';str.padStart(str.length+pasStr.length,pasStr) // "xxxapple"2.向后填充let str='apple';let pasStr='xxx';s...原创 2019-04-13 14:21:24 · 1962 阅读 · 0 评论 -
检测字符串内容的常用方法
str.startsWith(http); //字符串是否http开头 str.endsWith(png); //字符串是否png结尾 str.repeat(次数); //重复字符串原创 2019-04-13 14:03:16 · 1210 阅读 · 0 评论 -
Promise 实现队列
实现队列有时候我们不希望所有动作一起发生,而是按照一定顺序,逐个进行。let promise=doSomething();promise = promise.then(dosomethingElse);promise = promise.then(dosomethingElse);promise = promise.then(dosomethingElse);......使用...原创 2019-03-12 11:47:07 · 1511 阅读 · 1 评论 -
Promise.all() 和 .map()连用
查找最大文件const FileSystem=require('./FilesSystem');function(){ return FileSystem.readDir(dir,'utf-8') .then(files=>{ return Promise.all(files.map(file=>{ return new ...原创 2019-03-12 11:08:28 · 5398 阅读 · 0 评论 -
Promise.all()
批量执行Promise.all([p1,p2,p3,...])用于将多个Promise实例,包装成一个新的promise 实例。返回的实例就是普通Promise他接受一个数组作为参数数组里可以是Promise对象,也可以是别的值,只有Promise会等待状态改变。当所有的子Promise都完成,该Promise完成,返回值是全部值德 数组有任何一个失败,该promise失败...原创 2019-03-12 10:35:41 · 211 阅读 · 1 评论 -
Promise 错误和then连用
console.log('here we go')new Promise(resolve=>{ setTimeout(()=>{ resolve(); },1000)}) .then(()=>{ console.log('start'); throw new Error('test error') }).catch(er...原创 2019-03-11 17:05:41 · 3486 阅读 · 0 评论 -
Promise 错误处理
Promise 会自动捕获内部异常,并交给rejected响应函数处理。console.log('here we go');new Promise(resolve=>{ setTimeout(()=>{ throw new Error('bye'); },2000)}) .then(value=>{ console.log(v...原创 2019-03-11 16:47:50 · 1917 阅读 · 0 评论 -
Promise then的嵌套
.then() 里边有 .then()的情况因为 .then()返回的还是promise实例,会等里面的 .then()执行完,在执行外边的对于我们来说,此时最好将其展开,阅读体验更好,console.log('start')new Promise(resolve=>{ console.log('Step 1') setTimeout(()=>{ ...原创 2019-03-09 16:51:37 · 2125 阅读 · 0 评论 -
Promise 引出 .then()
.then() 接受两个函数作为参数,分别代表fulfilled和rejected.then() 返回一个新的Promise实例,所以他可以链式调用当前面的Promise状态改变时,.then()根据其最终状态,选择特定的状态响应函数执行状态响应函数可以返回新的Promise,或其它值如果返回新的Promise,那么下一级 .then()会在新的Promise状态改变之后执行...原创 2019-03-09 16:11:23 · 298 阅读 · 0 评论 -
then里不返回Promise
console.log('here we go')new Promise(resolve=>{ setTimeout(()=>{ resolve('hello') },2000);}) .then(value=>{ console.log(value) console.log('everyone'); ...原创 2019-03-09 15:56:03 · 1420 阅读 · 0 评论 -
对已完成的Promise执行then 查看效果
console.log("start")let promise=new Promise(resolve=>{ setTimeout(()=>{ console.log('the promise fulfilled') resolve('hello,wrold'); },1000) })setTi...原创 2019-03-09 15:38:03 · 691 阅读 · 0 评论 -
Pormise 的简单的实例
console.log('here wo go')new Promise(resolve=>{ setTimeout(()=>{ resolve('hello'); },2000)}) .then(value=>{ console.log(value + 'world') })实例2console.log(...原创 2019-03-09 15:16:01 · 3149 阅读 · 0 评论 -
Promise介绍
new Promise( // 执行器 executor function(resole,reject){ //一段耗时很长的异步操作 resolve(); //数据处理完成 reject(); //数据处理错误 }) .then(function A(){ //成功,下一步 },func...原创 2019-03-09 14:55:56 · 161 阅读 · 0 评论 -
es6 数组去重的方法
const array=[1,2,3,4,5,6,1,3,5,7];new Set(array) // {1,2,3,4,5,6,7}[...new Set(array)] // [1,2,3,4,5,6,7]Array.from(new Set(array)) // [1,2,3,4,5,6,7]原创 2019-01-02 10:47:23 · 437 阅读 · 0 评论