Function call and its effect this point

  • When calling a function, in addition to passing the parameters in the function definition explicitly declared outside, while passing two implicit parameters: arguments and this.
    • arguments parameter is a collection of all the parameters passed into the function. Having a length property, that is the number of parameters passed, those parameters may also be obtained with the function parameter arguments do not match the parameters through. In the non-strict model, the object is an alias function parameter arguments, modifications modify arguments object argument function, by avoiding modification strict mode function arguments.
    • this context indicates the object function, i.e., associated with the function call. And define how the function is called by the decision of this point.
  • There are 4 function is called in
    1. As a function call
    2. Invoked as an object method
    3. As a constructor call
    4. Call by call and apply methods
  • This function is called by the impact of values
    1. If called as a function, in non-strict mode, this points to the global object window; this point undefined in strict mode.
      • udnefined type [object Undefined]
      • Using this embodiment acquires specific data of the data type
        Object.prototype.toString.call(数据)
    2. As an object method calls, this usually points to the object call.
    3. As a constructor call, this usually points to the object (instance of an object) newly created.
    4. Call or apply by calling, this points to the first parameter of the call or apply.
  • Arrow functions no separate this value, determined in this function to create an arrow.
  • All functions can use the bind method, create a new function, and bound to the bind method parameters passed. Call the bind method does not modify the original function, but to create a new function.

Guess you like

Origin www.cnblogs.com/itxcr/p/11600183.html