1. this对象
this关键字指向调用者。
1.1 对象中的this
var info = {
name:"blank",
getName(){
console.log(this); // info
console.log(this === info) // true
console.log(this.name); // blank
}
}
info.getName();
1.2 闭包中的this
在闭包中,this对象是在运行时基于当前执行环境绑定的。
var name = "blankk";
var info = {
name:"blank",
getName(){
return function(){
console.log(this); // window
console.log(this === window) // true
console.log(this.name); // blankk
}
}
}
info.getName()();
1.3 定时器中的this
var time = 1;
var info = {
time:2,
getTime(){
setTimeout(function(){
console.log(this); // window
console.log(thi