当前位置:网站首页>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
边栏推荐
- 序列化、监听、自定义注解
- Installing Oracle EE
- js 使用toString 区分Object、Array
- 队列的实现和应用
- Set the type of the input tag to number, and remove the up and down arrows
- delete和delete[]引发的问题
- I use flask to write the website "one"
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
- js函数arguments对象
- Shell script case in statement
猜你喜欢

Ape anthropology topic 20 (the topic will be updated from time to time)

nacos服务配置和持久化配置

Phishing identification app

Principle and application of single chip microcomputer timer, serial communication and interrupt system
![[pytorch] softmax function](/img/97/b8ae22e8496a77e665d716cb0e9ee3.png)
[pytorch] softmax function

Football and basketball game score live broadcast platform source code /app development and construction project

How to manage fixed assets efficiently in one stop?

【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()

2.4 激活函数

How to realize the usage of connecting multiple databases in idel
随机推荐
2.4 激活函数
小鸟识别APP
NoSQL数据库的安装和使用
Shell script echo command escape character
LeetCode 344. Reverse string
钓鱼识别app
Installing Oracle EE
LogBack
樹結構---二叉樹2非遞歸遍曆
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
Shell script case in and regular expressions
类加载
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
Design and manufacture of simple digital display electronic scale
Learning practice: comprehensive application of cycle and branch structure (II)
【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
Understand shallow replication and deep replication through code examples
Shell script - positional parameters (command line parameters)
Naoqi robot summary 28
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统