toString.call(function(){})
// "[object Function]"
toString.call(null)
//"[object Null]"
toString.call([2])
"[object Array]"
toString.call(undefined)
//"[object Undefined]"
toString.call('stjd')
//"[object String]"
toString.call(1)
//"[object Number]"
toString.call(true)
//"[object Boolean]"
toString.call(Symbol(3))
// "[object Symbol]"
toString.call({q:8})
//"[object Object]"
原文链接:https://blog.csdn.net/qq_41831345/article/details/94428030
(...x)Rest 参数接受函数的多余参数,组成一个数组
function sum(x, y, m) {
let total = 0;
if (x) total += x;
if (y) total += y;
if (m) total += m;
console.log(`total:${total}`) //11
}
sum(5, 6)
let sum1 = (...x)=>{ //
let total=0;
for(var i of x)
{
total+=i;
}
console.log(`total:${total}`)
}
sum1(7,8,9) //24
...[4,5] //这就是扩展运算符 console.log(...[4,5]) //4 5
http://www.fly63.com/article/detial/2516
promise的用法
let checklogin = function() {
return new Promise((resolve, reject) => {
var flag = document.cookie.indexOf("user") != -1 ? true : false;
if (true) {
resolve({
status: "success",
})
}
})
}
let getUserInfor = ()=>{
return new Promise((resolve,reject)=>{
resolve({
name:"李四",
age:18
})
})
}
checklogin().then(res => {
if(res.status == "success")
{
return getUserInfor();
}
}).catch(err => {
console.log('失败')
}).then(res1=>{
console.log(`userInfor:${res1.name}`)
})
Promise.all([checklogin(),getUserInfor()]).then(([res1,res2])=>{
console.log(`res1:${res1.status}`)
})