function func(){ console.log(this); }
func();
2.2.经过对象.函数名()调用的--this指向这个对象 数组
狭义对象: this指向--obj app
var obj={ name:"obj", func1:func }; obj.func1();
广义对象: this指向--div函数
document.getElementById("div").onclick=function(){ this.style.backgroundColor="red"; }
2.3. this指向——数组arrthis
var arr=[func,1,2,3]; arr[0]();
2.4.函数做为window内置函数的回调函数调用,this指向window setInterval,setTimout等spa
setInterval(func,1000); setTimeout(func,1000)
2.6. 经过call、apply、bind调用,this指向咱们规定的对象。code
Func.call(obj,参数一,参数2,参数3.。。。)对象
Func.allply(obj,[ 参数一,参数2,参数3.。。。])blog
Func.bind(obj)( 参数一,参数2,参数3) var f = func.bind(obj). f(…….);get
var fullname = 'John Doe'; var obj = { fullname: 'Colin Ihrig', prop: { fullname: 'Aurelio De Rosa', getFullname: function() { return this.fullname; } } }; console.log(obj.prop.getFullname()); // Aurelio De Rosa //函数最终调用者:obj.prop this--->obj.prop
var test = obj.prop.getFullname; console.log(test()); // John Doe // 函数最终调用者: 函数() window this-->window