es6学习总结
this指向问题
es5中一句话可有概括谁调用this就指向谁(运行时生效),es6中箭头函数中没有this,所以es6中的this相当于一个变量,她永远继承外层作用域的this(定义时生效),需要注意的对象不构成作用域,当然函数在生效时才能行车作用域。
function f(){
this.s1=18;
this.s2=19;
setInterval(()=>this.s1++,1000);
setInterval(function func(){
this.s2++
},1000)
}
var obj=new f()
setTimeout(()=>{console.log("s1:",obj.s1)},3000)
setTimeout(()=>{console.log("s2:",obj.s2)},3000)
//21
//19 借鉴官网的例子
promise的链式调用
function china(){
console.log('china中国')
var p =new Promise(
function( resolve,reject ) {
setTimeout(function(){
// console.log('中国 国家')