ES6笔记总结
常用命令
- 函数的rest参数和扩展
- promise使用
- module.exports和Es6 import/export的使用
function sum(x,y,z){ let total = 0; if(x)total+=x; if(y)total+=y; if(z)total+=z; } sum(5,"",9); function sum2(...m){ let total = 0; for(var i of m){ total += i; } console.log(`total${total}`) } sum2(4,8,9,10,5); let sum3 = (...m)=>{ let total = 0; for(var i of m){ total += i; } console.log(`total${total}`) } sum3(4,8,9,10,5); var [x,y] = [4,8]; console.log(...[4,8]) let arr1 = [1,3]; let arr2 = [4,8]; console.log("concat:"+arr1.concat(arr2)); //[...arr1,...arr2]; let [a,b,c]="ES6"; console.log(a);//输出E
let checkLogin = function(){ return new Promise(function(resolve,reject){ let flag = document.cookie.indexOf("userId")>-1?true:false; if(flag=true){ resolve({ status :0, result:true }) }else{ reject("error") } }) }; let getUserInfo = ()=>{ return new Promise((resolve,reject)=>{ let userInfo={ userId:"101 " } resolve(userInfo); }) }; checkLogin().then((res)=>{ if(res.status == 0){ console.log("login success") return getUserInfo(); } }).catch((error)=>{ console. log(`error:${error}`); }).then((res2)=>{ console.log(`userId${res2.userId}`) }) Promeise.all([checkLogin(),getUserInfo( )]).then(([res1,res2])=>{ console.log(`result:${res1.result},result:${res2.result}`) })
//promise let checkLogin = function(){ return new Promise(function(resolve,reject){ let flag = document.cookie.indexOf("userId")>-1?true:false; if(flag=true){ resolve({ status:0, result:true }) }else{ reject("error") } }) }; let getUserInfo = ()=>{ return new Promise((resolve,reject)=>{ let userInfo={ userId:"101" } resolve(userInfo); }) }; checkLogin().then((res)=>{ if(res.status == 0){ console.log("login success") return getUserInfo(); } }).catch((error)=>{ console.log(`error:${error}`); }).then((res2)=>{ console.log(`userId${res2.userId}`) }); Promeise.all([checkLogin(),getUserInfo()]).then(([res1,res2])=>{ console.log(`result:${res1.result},result:${res2.result}`) })
ES6笔记总结的更多相关文章
- ES6笔记(5)-- Generator生成器函数
系列文章 -- ES6笔记系列 接触过Ajax请求的会遇到过异步调用的问题,为了保证调用顺序的正确性,一般我们会在回调函数中调用,也有用到一些新的解决方案如Promise相关的技术. 在异步编程中,还 ...
- ES6笔记系列
ES6,即ECMAScript 6.0,ES6的第一个版本是在2015年发布的,所以又称作ECMAScript 2015 如今距ES6发布已经一年多的时间,这时候才去学,作为一个JSer,羞愧羞愧,还 ...
- ES6笔记(1) -- 环境配置支持
系列文章 -- ES6笔记系列 虽然ES6已经发布一年多了,但在各大浏览器之中的支持度还不是很理想,在这查看ES6新特性支持度 Chrome的最新版本浏览器大部分已经支持,在Node.js环境上支持度 ...
- ES6笔记(2)-- let的块级作用域
系列文章 -- ES6笔记系列 一.函数级作用域 我们都知道,在ES6以前,JS只有函数级作用域,没有块级作用域这个概念 没有块级作用域,有利有弊,利于方便自由,弊于作用域内的变量容易被共享,例如这个 ...
- ES6笔记(3)-- 解构赋值
系列文章 -- ES6笔记系列 解构赋值,即对某种结构进行解析,然后将解析出来的值赋值给相关的变量,常见的有数组.对象.字符串的解构赋值等 一.数组的解构赋值 function ids() { ret ...
- ES6笔记(4)-- Symbol类型
系列文章 -- ES6笔记系列 Symbol是什么?中文意思是标志.记号,顾名思义,它可以用了做记号. 是的,它是一种标记的方法,被ES6引入作为一种新的数据类型,表示独一无二的值. 由此,JS的数据 ...
- ES6笔记(6)-- Set、Map结构和Iterator迭代器
系列文章 -- ES6笔记系列 搞ES6的人也是够无聊,把JS弄得越来越像Java.C++,连Iterator迭代器.Set集合.Map结构都出来了,不知道说什么好... 一.简单使用 1. iter ...
- ES6笔记(7)-- Promise异步编程
系列文章 -- ES6笔记系列 很久很久以前,在做Node.js聊天室,使用MongoDB数据服务的时候就遇到了多重回调嵌套导致代码混乱的问题. JS异步编程有利有弊,Promise的出现,改善了这一 ...
- ES6 笔记汇总
ES6 笔记汇总 二.ES6基础-let和const命令 三.变量的解构赋值 四.字符串的拓展 五.正则表达式的拓展 ...将会持续更新,敬请期待
- ES6笔记2
ES6笔记2 Promise Promise 是 ES6 引入的异步编程的新解决方案,语法上是一个构造函数 一共有3种状态,pending(进行中).fulfilled(已成功)和rejected(已 ...
随机推荐
- 区分拖曳(drag)和点击(click)事件
假设页面上有一个a标签: <a href="http://www.google.com">google</a> 现在需要对这个标签进行拖放操作,会发现当拖曳 ...
- ListView的异步载入(笔记,多线程和AsyncTask)
异步载入最经常使用的两种方式: 多线程,线程池 AsyncTask 实例操作: 从一个站点上获取Json数据.然后将数据在ListView上显示. 1.创建item_layout布局 , 改动 ...
- return和exit的差别
#include<stdio.h> #include<sys/types.h> #include<sys/wait.h> #include<unistd.h& ...
- multiTarget within one project pods manage
step1:file->new->target create 1 targetstep2:change Podfile and update podstep3:check new targ ...
- CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂
题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...
- rc.local 开启自启动,检测是否成功
rc.local /etc/init.d/nginx start 查看运行状态 systemctl status rc-local ● rc-local.service - /etc/rc.local ...
- 理解HTML解析过程
浏览器解析html的过程是:接受网络数据->将二进制码变成字符->将字符变为unicode code points.->tokenizer ->tree constructor ...
- BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...
- linux应用之基本命令
linux操作系统的应用层可以细分为两层:1.系统服务层(包括GUI shell.CUI shell.cron.ftp.远程登录openssh等由init调用的服务)2.系统命令和用户应用. linu ...
- XML简介——可扩展标记语言(Extensible Markup Language)
(What) XML是什么? XML指可扩展标记语言(Extensible Markup Language) 1. XML是一种标记语言,类似HTML. 2. XML具有自我描述性 3. XML ...