当前位置:网站首页>Yyds dry goods count re comb this of arrow function
Yyds dry goods count re comb this of arrow function
2022-07-06 20:42:00 【51CTO】
I remember sharing before this Usage of , It's about ordinary functions 、 Constructor's this, Today's main share ES6 Arrowhead function this. Let's first look at this.
Under ordinary function this:
- In ordinary functions this Always represents its direct caller , By default ,this refer to window,
- In strict mode , There is no direct caller in the function of this yes undefined Use
- call,apply,bind(ES5 newly added ) The binding of ,this refer to Bound object
In the arrow function this:
- Arrow function does not have its own this, its this It's inherited ; By default, it points to the object where it was defined ( Host object ),
- Not the object at execution time , When you define it , Maybe the environment is window, It could be something else .
Ordinary function
test It's a global function , That is to mount on window Under the object test() Equivalent to window.test();
func The host environment is obj, therefore func Inside this yes obj. Functions in timer , Because there is no default host object , therefore this Point to window In strict mode this:
Strict mode
In strict mode , There is no direct caller in the function of this yes undefined
With direct callers this Is its caller
Arrow function
At this time this Inherited from obj, It refers to the object that defines it obj, instead of window
because f1 The function in which it is defined Medium this It means obj, setTimeout Arrow function in this Inherited from f1, So no matter there are multiple nesting , All are obj
The arrow function doesn't this The binding of , Its value must be determined by looking up the action chain . If the arrow function is contained by a non arrow function , be this Bound is the latest layer of non arrow functions this; otherwise .this The value of will be set to undefined. When defining an arrow function, its environment is equivalent to window, So inside the arrow function this function window.
边栏推荐
- Application layer of tcp/ip protocol cluster
- [weekly pit] information encryption + [answer] positive integer factorization prime factor
- Error analysis ~csdn rebound shell error
- [asp.net core] set the format of Web API response data -- formatfilter feature
- 报错分析~csdn反弹shell报错
- Force deduction brush question - 98 Validate binary search tree
- [wechat applet] operation mechanism and update mechanism
- "Penalty kick" games
- 【每周一坑】输出三角形
- Appx code signing Guide
猜你喜欢
What key progress has been made in deep learning in 2021?
Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
Ideas and methods of system and application monitoring
棋盘左上角到右下角方案数(2)
Entity alignment two of knowledge map
Leetcode question 283 Move zero
[DIY]自己设计微软MakeCode街机,官方开源软硬件
Redis insert data garbled solution
Trends of "software" in robotics Engineering
SSO single sign on
随机推荐
Leetcode question 283 Move zero
Trends of "software" in robotics Engineering
[diy] self designed Microsoft makecode arcade, official open source software and hardware
[wechat applet] operation mechanism and update mechanism
Anaconda安裝後Jupyter launch 沒反應&網頁打開運行沒執行
小孩子学什么编程?
【每周一坑】输出三角形
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Spark SQL chasing Wife Series (initial understanding)
(work record) March 11, 2020 to March 15, 2021
C language games - three chess
Force deduction brush question - 98 Validate binary search tree
Continuous test (CT) practical experience sharing
Rhcsa Road
【每周一坑】计算100以内质数之和 +【解答】输出三角形
Jupyter launch didn't respond after Anaconda was installed & the web page was opened and ran without execution
7. Data permission annotation
Application layer of tcp/ip protocol cluster
Pycharm remote execution