This article mainly introduces the new understanding of this pointer in JavaScript. this article describes the method call mode, function call mode, constructor call mode, and the understanding of this pointer in the Apply call mode, if you need this, you can refer to the previous understanding of this. This time, I made a deep understanding through JavaScript The Good Parts. (ALL debugging tasks can be viewed on the console, with the F12 key in the browser)
Let's take a look at this.
When we declare a function, each function has two additional parameters besides the parameters parameter in definition. One is this and the other is arguments ). Arguments is the parameter actually accepted by the function and is an array of classes. Arguments I will only give a brief introduction, focusing on the this pointer.
This is very important in object orientation. Its value depends on the call mode. In JavaScript, there are 4 call modes: method call mode, function call mode, constructor call mode, and apply call mode.
Method call mode
When a function is an object attribute, we usually call this function a method of this object. When this method is called, this points to the object to which the method belongs.
The Code is as follows: