当前位置:网站首页>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.
边栏推荐
- 02 基础入门-数据包拓展
- Pycharm remote execution
- 8086 instruction code summary (table)
- [weekly pit] calculate the sum of primes within 100 + [answer] output triangle
- OLED屏幕的使用
- Recyclerview GridLayout bisects the middle blank area
- 【微信小程序】运行机制和更新机制
- Deep learning classification network -- zfnet
- Detailed explanation of knowledge map construction process steps
- In unity space, an object moves around a fixed point on the sphere at a fixed speed
猜你喜欢

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

Error analysis ~csdn rebound shell error

【OpenCV 例程200篇】220.对图像进行马赛克处理

B-jiege's tree (pressed tree DP)

Jupyter launch didn't respond after Anaconda was installed & the web page was opened and ran without execution

Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)

使用.Net驱动Jetson Nano的OLED显示屏
![Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]](/img/cf/58a62a7134ff5e9f8d2f91aa24c7ac.png)
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]

为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?

Core principles of video games
随机推荐
How to upgrade high value-added links in the textile and clothing industry? APS to help
小孩子学什么编程?
C language operators
use. Net drives the OLED display of Jetson nano
Taylor series fast Fourier transform (FFT)
棋盘左上角到右下角方案数(2)
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条
OLED屏幕的使用
Rhcsa Road
OLED屏幕的使用
Minimum cut edge set of undirected graph
基于STM32单片机设计的红外测温仪(带人脸检测)
Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle
逻辑是个好东西
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
Special topic of rotor position estimation of permanent magnet synchronous motor -- Summary of position estimation of fundamental wave model
Digital triangle model acwing 1018 Minimum toll
知识图谱构建流程步骤详解
Maximum likelihood estimation and cross entropy loss
Tencent T4 architect, Android interview Foundation