当前位置:网站首页>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.
边栏推荐
- 小孩子學什麼編程?
- 2022 nurse (primary) examination questions and new nurse (primary) examination questions
- Discussion on beegfs high availability mode
- 【每周一坑】信息加密 +【解答】正整数分解质因数
- 【OpenCV 例程200篇】220.对图像进行马赛克处理
- Entity alignment two of knowledge map
- 8086 instruction code summary (table)
- Variable star --- article module (1)
- Extraction rules and test objectives of performance test points
- 动态切换数据源
猜你喜欢

2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third

Number of schemes from the upper left corner to the lower right corner of the chessboard (2)

Boder radius has four values, and boder radius exceeds four values

“罚点球”小游戏

Use of OLED screen

Common doubts about the introduction of APS by enterprises

拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条

OAI 5G NR+USRP B210安装搭建

使用.Net驱动Jetson Nano的OLED显示屏

Spark SQL chasing Wife Series (initial understanding)
随机推荐
Dynamically switch data sources
PHP online examination system version 4.0 source code computer + mobile terminal
Notes on beagleboneblack
Leetcode question 448 Find all missing numbers in the array
Error analysis ~csdn rebound shell error
15 millions d'employés sont faciles à gérer et la base de données native du cloud gaussdb rend le Bureau des RH plus efficace
Comment faire une radio personnalisée
Variable star --- article module (1)
Spiral square PTA
OLED屏幕的使用
I've seen many tutorials, but I still can't write a program well. How can I break it?
Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
User defined current limiting annotation
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
知识图谱之实体对齐二
Catch ball game 1
报错分析~csdn反弹shell报错
In unity space, an object moves around a fixed point on the sphere at a fixed speed
Rhcsa Road