Arrow function summary

Introduction: For this function arrow s6 been a bit vague, would like to briefly summarize some of the questions about this point:

1. Arrow function does not own this: when this function instead of calling the arrows bound, but the time in which the object function definition

Example 1:

 General function of this: the current button DOM object

 Arrow function in this: because the current time function is defined in the window, so this point to call the object instead of the current window

 2. Check the current outer function has no function, any current function of this points to the outer function in this

 Example 2:

 

 

 General Functions in this outer point of the object obj call it, this arrow and function of this point in the same outer function.

 Similarly, if the outer layer also functions to arrow functions:

 

 

 GetName outer function is a function of an arrow, which points to this window; inner function also point window.

3. The arrows define a constructor function can not

 

 Error:

 

 

 4. Arrow function captures this value as its own this context, so the use of call () / applay () / bind () method does not change this point

 

 

 

Guess you like

Origin www.cnblogs.com/zxmonster/p/11881282.html