ES6的常用功能

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})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值