this指向
一、改变this指向的方法:
1、箭头函数 ======》只适合最新版本的浏览器;
2、bind() ======》不兼容低版本的IE
3、var _this = this ======》兼容所有浏览器
二、不同环境下的this的指向:
1、this的指向是在函数运行时确定下来的,而不是创建的时候,谁调用就指向谁。如:
2、构造函数内部的this必须指向new出来的这个对象,而不是div对象(打印出来必须是对象,而不能是div)。 如:
function Popup(){
this.name = '李四';
this.say = function(){
console.log('哈哈')
}
}
var oPopup = new Popup();