call() and apply()
- These two methods are methods of the function object and need to be called through the function object
- When calling a function call() and apply() will call the function to execute
- When calling call() and apply(), you can specify an object as the first parameter.
At this time, this object will become the this when the function is executed. - The call() method can pass the actual parameters in turn after the object
- The apply() method needs to encapsulate the actual parameters into an array and pass them uniformly
the case of this
1. When called in the form of a function, this is always window
2. When called in the form of a method, this is the object that calls the method
3. When called in the form of a constructor, this is the newly created object
4. Use call and When apply is called, this is the specified object
arguments
When calling a function, the browser will pass two implicit parameters
1. The context object of the function this
2. The object that encapsulates the arguments
- Arguments is an array-like object, you can also manipulate data by index, or you can get the length
- Even if you do not define formal parameters, you can use arguments to use
arguments. Arguments[0] represents the first
argument, arguments[1] represents the second argument - When calling the function, the actual parameters we pass will be saved in arguments
- There is an attribute in arguments called callee, this attribute corresponds to a function object, which is the function object currently being pointed to