当前位置:网站首页>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.
边栏推荐
- Utilisation de l'écran OLED
- Web security - payload
- 01 基础入门-概念名词
- Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great
- 报错分析~csdn反弹shell报错
- Quel genre de programmation les enfants apprennent - ils?
- 小孩子学什么编程?
- Force deduction brush question - 98 Validate binary search tree
- Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
- Taylor series fast Fourier transform (FFT)
猜你喜欢
![[wechat applet] operation mechanism and update mechanism](/img/cf/58a62a7134ff5e9f8d2f91aa24c7ac.png)
[wechat applet] operation mechanism and update mechanism

Utilisation de l'écran OLED

Web security - payload

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

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

Variable star --- article module (1)

【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和

SQL injection 2

【DSP】【第二篇】了解C6678和创建工程

【每周一坑】信息加密 +【解答】正整数分解质因数
随机推荐
Tencent T4 architect, Android interview Foundation
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
Application layer of tcp/ip protocol cluster
Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
C language operators
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
[weekly pit] output triangle
[weekly pit] information encryption + [answer] positive integer factorization prime factor
小孩子學什麼編程?
Catch ball game 1
Ideas and methods of system and application monitoring
【微信小程序】运行机制和更新机制
设计你的安全架构OKR
B-杰哥的树(状压树形dp)
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
电子游戏的核心原理
Notes on beagleboneblack
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
Leetcode hot topic Hot 100 day 32: "minimum coverage substring"