当前位置:网站首页>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.
边栏推荐
- Leetcode question 283 Move zero
- 【微信小程序】运行机制和更新机制
- [wechat applet] operation mechanism and update mechanism
- Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
- Rhcsa Road
- "Penalty kick" games
- 01 basic introduction - concept nouns
- Taylor series fast Fourier transform (FFT)
- Error analysis ~csdn rebound shell error
- 【微信小程序】運行機制和更新機制
猜你喜欢

小孩子学什么编程?

【微信小程序】运行机制和更新机制

SQL injection 2

知识图谱之实体对齐二

基于STM32单片机设计的红外测温仪(带人脸检测)

Discussion on beegfs high availability mode

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

使用.Net分析.Net达人挑战赛参与情况

Deep learning classification network -- zfnet

为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
随机推荐
PHP online examination system version 4.0 source code computer + mobile terminal
【OpenCV 例程200篇】220.对图像进行马赛克处理
【每周一坑】信息加密 +【解答】正整数分解质因数
In line elements are transformed into block level elements, and display transformation and implicit transformation
How to turn a multi digit number into a digital list
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)
Recyclerview GridLayout bisects the middle blank area
C language games - minesweeping
Distributed ID
Unity making plug-ins
Review questions of anatomy and physiology · VIII blood system
Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
Comment faire une radio personnalisée
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100
看过很多教程,却依然写不好一个程序,怎么破?
Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle
Gui Gui programming (XIII) - event handling
Detailed explanation of knowledge map construction process steps
B-杰哥的树(状压树形dp)