当前位置:网站首页>This point of arrow function
This point of arrow function
2022-06-11 06:06:00 【No baldness】
Statement :call、apply、bind Can't change the arrow function this Point to
for example :
const fun1 = ()=>{
console.log(this === window)
}
const person = {
name:'tom'
}
fun1() // true
fun1.apply(person) // true
fun1.bind(person) // true
fun1.call(person) // true
You can see that the arrow function initially points to window, Use apply、bind、call To try to change its direction , They all failed , Always point to window
Conclusion : The arrow function points to the object that is its grandfather . That is, the parent object of the parent .
prove :
const obj = {
name:'obj',
fun1:function (){
return setTimeout(()=>{
console.log(this.name)
},1000)
}
}
const person = {
name:'person',
age:'22'
}
obj.fun1() // obj
obj.fun1.apply(person) //person
You can see , We are setTimeout The arrow function is called ,setTimeout Is a global function , It points to window, Then we were obj Object setTimeout, Arrowhead function this Parent pointing to parent , Here, it points to obj
It was said that , We cannot change the direction of the arrow function , But we can change the direction of its parent , Because the arrow function points to the parent of the parent , It means that we have changed the direction of the arrow function . In the example, we changed fun1 The direction of , Successfully changed the direction of the arrow function .
边栏推荐
- Using Internet of things technology to accelerate digital transformation
- FPGA interview notes (III) -- implementation of handshake signal synchronization in cross clock domain, arbitrary frequency division, binary conversion, RAM memory, original code inversion and complem
- Sword finger offer 04: find in 2D array
- Thymeleafengine template engine
- Using batch enumeration files
- Jsonobject jsonarray for parsing
- FPGA面试题目笔记(四)—— 序列检测器、跨时钟域中的格雷码、乒乓操作、降低静动态损耗、定点化无损误差、恢复时间和移除时间
- 使用Genymotion Scrapy控制手机
- Elk log system practice (VI): comparison between vector and filebeat for technology selection
- Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset
猜你喜欢

“All in ONE”一个平台解决所有需求,运维监控3.0时代已来

Pycharm usage experience

Compliance management 101: processes, planning and challenges

The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it

FIFO最小深度计算的题目合集

Cocoatouch framework and building application interface
![Chapter 2 of machine learning [series] logistic regression model](/img/8f/b4c302c0309f5c91c7a40e682f9269.jpg)
Chapter 2 of machine learning [series] logistic regression model

FPGA面试题目笔记(一)——FPGA开发流程、亚稳态和竞争冒险、建立保持时间、异步FIFO深度等

Stock K-line drawing

Use com youth. banner. Solution to the inflateexception reported by the banner plug-in
随机推荐
Get the value of program exit
Error reporting injection of SQL injection
Altiumdesigner2020 import 3D body SolidWorks 3D model
Utiliser le fichier Batch Enum
The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it
Servlet
Login and registration based on servlet, JSP and MySQL
FPGA面試題目筆記(四)—— 序列檢測器、跨時鐘域中的格雷碼、乒乓操作、降低靜動態損耗、定點化無損誤差、恢複時間和移除時間
Summarize the five most common BlockingQueue features
MinGW-W64安装说明
What happened to the young man who loved to write code -- approaching the "Yao Guang young man" of Huawei cloud
Observer mode (listener mode) + thread pool to realize asynchronous message sending
DISM命令使用小结
NFC Development -- utility tools and development documents (IV)
數組部分方法
Moteur de modèle de moteur thymeleaf
Configure the rust compilation environment
Clojure installation of metabase source code secondary development
箭头函数的this指向
Excellent practice | how to avoid a bloody case caused by a line of wrong code?