一,普通函数中的this指向,
二,定时器方法中的this指向,
三,构造函数中的this指向,
四,对象方法中的this指向,
五,原型中的this指向
function obj(){
console.log(this);
}
obj();
window
<!定时器中的this指向>
setInterval(function (){
console.log(this);
},300)
window
function Person(){
console.log(this);
}
var person1=new Person();
Person
// 对象方法中的this指向实例对象
function Person(){
console.log(this);
this.say=function(){
console.log(this);
}
}
var person1=new Person();
person1.say();
Person {}
Person {say: ƒ}
<!--原型方法中的this指向实例对象-->
function Person() {
Person.prototype.sayHi=function(){
console.log(this);
}
}
var person1=new Person();
person1.sayHi();
Person
网友评论