(1) When a function is called, this points to window; (2) when the constructor is called, this refers to the instance object. (3) when the method is called, this refers to the object to which the method belongs. (4) Through the event binding method, this refers to the object bound to the event; The timer function, this refers to the window;

Call,apply,bind,bind,bind,bind,bind,bind

Call and bind are passed to each other in sequence. But apply only takes two arguments, and the second argument is an array; Both call and apply are direct calls to functions, whereas bind still returns a function.

Such as:var a ={
	name:'dream a dream'.age:'22'.sex:'woman'.hobby:'Write code'
	say:function(sex,hobby) {         
		console.log(this.name,this.age,sex,hobby)      
	}
}
var b = {
	name:'I I'.age:'23',
}
a.say.call(b,'male'.'learning');
a.say.apply(b,['male'.'learning']) bind can be passed in the same way as cally: for example: a.say.bind(b,'male'.'learning') (); But since bind still returns a function, we can pass the arguments when we call it. For example: a.s ay. Bind (b) ('male'.'learning');
// The result is: "Chen Chen ","23"," male "," study"
Copy the code