for(var i=0; i<5; i++){
    setTimeout(()=>{console.log(i)}, i*1000)
}
每隔1秒输出5
//5
//5
//5
//5
//5
var seller = {
    count: 2,
    getCount: function(){
        return this.count
    }
}
var func = seller.getCount  
console.log(seller.getCount())  //2  
console.log(func())    //undefined
var seller = {
    count: 2,
    getCount: function(){
        var self = this
        console.log('1', this.count);  //2
        console.log('2', self.count);  //2
        (function(){     //闭包
            console.log('3', this.count) //undefined
            console.log('4', self.count) //2
        })()
    }
}
seller.getCount()
'use strict'
var a = 1
var b = 2
var add = function(a,b){
    return this.a + this.b  //严格模式下,this为undefined
}
console.log(add(1,2))  //报错
var a = 1
var b = 2
var add = function(a,b){
    return this.a + this.b
}
console.log(add(1,2))   //3

 

posted on 2021-09-24 15:34  李起桉  阅读(18)  评论(0编辑  收藏  举报