Class函数
- https://blog.csdn.net/qq_43558102/article/details/101058943**
Promise
- https://blog.csdn.net/qq_43558102/article/details/100888191
let/const let定义可以被重新赋值,const定义的常量则不行
- 多行字符串/模板变量 拼接更加简单
var name = "zhangsan", age =20, html="";
html += "<div>"
html += "<p> + name +</p>"
html += "<p> + age +</p>"
html += "</div>"
const name = "zhangsan" , age = 20;
const html = `<div>
<p>${name}</p>
<p>${age}</p>
</div>
`;
解构赋值
var obj = {a:100 , b:200}
var a = obj.a
var b = obj.b
var arr = ["xxx" , "yyy" , "zzz"]
var x = arr[0]
var z = arr[2]
const obj = {a:100 , b:200}
const{a,b} = obj;
const arr = ["xxx" , "yyy" ,"zzz"]
const [x, y, z] = arr
块级作用域
var obj = {a:100 , b:200}
for(let item in obj){
console.log(item)
}
console.log(item)
**函数默认参数**
function fn(a , b){
if(b = null){
b=0
}
}
function fn(a , b=0)
箭头函数
var arr = [1, 2, 3];
arr.map(function(item){
return item + 1
})
const arr = [1, 2, 3];
arr.map(item => item+1)
arr.map((item , index) =>{
console.log(item);
return item + 1
})
function fn(){
console.log("real" , this) //real {a:100}
var arr = [1,2,3]
arr.map(function(item){
console.log(this) //this此时指向window
})
}
fn.call({a:100})
function fn(){
console.log("real" , this) //real {a:100}
var arr = [1,2,3]
arr.map(item => {
console.log(this) //{a:100}
})
}
fn.call({a:100})