JavaScript keyword this:
this
this is a keyword of JavaScript language. It is an object automatically generated inside the function body when the function is running. It can only be used inside the function body.
function test() {
this.x = 1;
}
Multiple directions of this:
In JavaScript, this is not fixed. It will change with the change of execution environmen ...
Posted by koopmaster on Mon, 07 Mar 2022 15:04:16 +0100
JavaScript changes this to point to - apply, call, bind
Formally speaking, these three methods can hijack the methods of another object and inherit the properties of another object. Generally speaking, it can change the direction of this.
1,apply
1. Basic use
Syntax: apply(T,A) T: Change the direction of this A: Passed parameter, array type Specific demonstration:
window.name = 'window'
...
Posted by heldenbrau on Thu, 03 Mar 2022 21:31:57 +0100
The call() apply() bind() method in JS changes this
We all know the direction of this: Always adhere to a principle: this always points to the object that was invoked at last, because the object of calling function is different, which leads to the different direction of this.
However, the direction of this can be changed by using call apply bind:
call method
Syntax: fun call(thisArg, arg1, ...
Posted by maheshbaba on Wed, 05 Jan 2022 06:40:19 +0100