当前位置:网站首页>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.
边栏推荐
- Pytest (3) - Test naming rules
- Dynamically switch data sources
- 【DSP】【第二篇】了解C6678和创建工程
- Rhcsa Road
- What key progress has been made in deep learning in 2021?
- C language games - three chess
- [wechat applet] operation mechanism and update mechanism
- 报错分析~csdn反弹shell报错
- 【微信小程序】運行機制和更新機制
- Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
猜你喜欢

Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model

The mail command is used in combination with the pipeline command statement

硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件

Basic knowledge of lists
![[diy] self designed Microsoft makecode arcade, official open source software and hardware](/img/a3/999c1d38491870c46f380c824ee8e7.png)
[diy] self designed Microsoft makecode arcade, official open source software and hardware

Learn to punch in Web

I've seen many tutorials, but I still can't write a program well. How can I break it?

Logic is a good thing

1_ Introduction to go language

Trends of "software" in robotics Engineering
随机推荐
Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
【每周一坑】信息加密 +【解答】正整数分解质因数
Error analysis ~csdn rebound shell error
【每周一坑】输出三角形
[DIY]自己设计微软MakeCode街机,官方开源软硬件
C language games - minesweeping
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
Initial experience of addresssanitizer Technology
JS implementation force deduction 71 question simplified path
Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
#yyds干货盘点#重新梳理箭头函数的this
解剖生理学复习题·VIII血液系统
8086 instruction code summary (table)
报错分析~csdn反弹shell报错
Zoom with unity mouse wheel: zoom the camera closer or farther
Why do novices often fail to answer questions in the programming community, and even get ridiculed?
Function optimization and arrow function of ES6
Tencent T4 architect, Android interview Foundation
APS taps home appliance industry into new growth points
[DIY]如何制作一款個性的收音機