1.函数调用模式
function func(){ console.log(this); //window } func(); var func = function(){ console.log(this); //window }
2.方法调用模式
var func = function(){ console.log(this); //被调用的对象 o } var o = {}; o.fn = func; o.fn();
3.构造器调用模式
var Person = function(){ this.name = "fucker"; this.do = function(){ console.log('how to fuck!') }; }; var p = new Person(); p.do(); this指的是对象本身P,即当前对象
4.apply与call调用模式
apply中的this可以随意指定 func.apply(null); // this ->window func.apply(o,[]); //this -> o
func.call(null); // this ->window
func.call(o,'',''); //this -> o