当前位置:网站首页>Analysis and solution of JS this loss
Analysis and solution of JS this loss
2022-07-01 09:17:00 【su27_ 0101】
this Lost Cases
var obj = {
name: "Mike",
sayHi: function(){
console.log(this.name + " say Hi !");
}
}
setTimeout(obj.sayHi, 1000);// undefined say Hi
Because of the this Always point to its caller 1s after call sayHi yes window but window Not so much therefore by undefined
Solution
Nested functions
- setTimeout(function(){obj.sayHi()}, 1000);// undefined say Hi
Use bind modify this Point to
- setTimeout(obj.sayHi.bind(obj), 1000);// undefined say Hi
边栏推荐
- [pytorch] 2.4 convolution function nn conv2d
- js函数arguments对象
- [ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
- 短路运算符惰性求值
- Microcomputer principle - bus and its formation
- Shell script - definition, assignment and deletion of variables
- dsPIC30F6014a LCD 方块显示
- 计网01-物理层
- Leetcode daily question brushing record --540 A single element in an ordered array
- Pain points and solutions of equipment management in large factories
猜你喜欢
![[pytorch] softmax function](/img/97/b8ae22e8496a77e665d716cb0e9ee3.png)
[pytorch] softmax function

Daily practice of C language - day 80: currency change

Principle and application of single chip microcomputer timer, serial communication and interrupt system

js作用域链与闭包

树结构---二叉树2非递归遍历

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

NoSQL数据库的安装和使用

MySQL optimization

【电赛训练】红外光通信装置 2013年电赛真题

Why is the Ltd independent station a Web3.0 website!
随机推荐
Ape anthropology topic 20 (the topic will be updated from time to time)
How to manage fixed assets efficiently in one stop?
R language observation log (part24) -- initialization settings
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
PR training notes
Shell script - special variables: shell $, $*, [email protected], $$$
Niuke monthly race 22- collect pieces of paper
Databinding source code analysis
Simple load balancing with Nacos
Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
Shell script -select in loop
3D printing Arduino four axis aircraft
Record a redis timeout
FAQ | FAQ for building applications for large screen devices
MySQL optimization
【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
Shell script echo command escape character
Which method is good for the management of fixed assets of small and medium-sized enterprises?
Installation and use of NoSQL database
Mysql8.0 learning record 17 -create table