Call the event function inside the tag
This refers to whoever calls the function in which this is located
1. If this is passed as an argument, this refers to input
2. If this is not passed in the tag’s method, the method prints this pointing to the window
Onclick event this (return the tag)
Constructor this (this refers to the specific object being instantiated (this refers to whoever calls this function).
function fn(name,sex,age){
this.name = name;
this.sex = sex;
this.age = age;
}
var a = new fn('Ming'.'male'.18);
Copy the code
Print the value of a:
This refers to whoever calls the function in which this is called.
Array.prototype.pt = function() {
console.log(this)}var a = [1.2.3.4]
console.log(a.pt()) // (4) [1, 2, 3, 4]
Copy the code
This in the object method
Object == ordinary properties + method properties
Here this refers to obj(this refers to whoever calls this.)
var obj = {
name:'Joe'.fn:function(){
console.log("Hello, my name is."+this.name); /// Hello, my name is Zhang SAN}}Copy the code