settimeout中的函数this指向window
来源:互联网 发布:网络语言20米是多少钱 编辑:程序博客网 时间:2024/06/05 09:52
var obj = { name: 'name', foo: function () { console.log(this); // Object {name: "name"} setTimeout(function () { console.log(this); // Window }, 1000); }, foo2: function () { console.log(this); // Object {name: "name"} setTimeout(() => { console.log(this); // Object {name: "name"} }, 2000); }}
先说结论:setTimeout中所执行函数中的this,永远指向window!!注意是要延迟执行的函数中的this哦!!
var obj = { name: 'name', foo: function () { console.log(this); // Object {name: "name"} setTimeout(function () { console.log(this); // Window }, 1000); }, foo2: function () { console.log(this); // Object {name: "name"} setTimeout(() => { console.log(this); // Object {name: "name"} }, 2000); }, foo3: function(){ console.log(this); setTimeout(function(){console.log(this);}.bind(this), 2000) }}
阅读全文
0 0
- settimeout中的函数this指向window
- setInterval和setTImeout中的this指向问题
- setInterval和setTimeout函数中This的指向问题
- 关于setInterval和setTImeout中的this指向问题
- 关于setInterval和setTImeout中的this指向问题
- setTimeout中this的指向,使用箭头函数后this的指向
- setTimeout中this指向问题
- js setTimeout 延迟函数中的this
- 嵌套函数中的this指向的对象
- JS-箭头函数中的this的指向
- JS函数中的this指向问题
- setTimeOut中的this问题
- setTimeout中this指向全局windows
- 函数调用模式,this在函数中的指向
- 函数中的this指向,以及 修改this指向的 call/apply/bind方法
- javascript中的this指向
- js中的this指向
- JS中的this指向
- WOJ1043-Magic Star
- Linux静态链接库,动态链接库,动态加载库
- python
- 51nod1344-贪心&进制思想&好题-砝码称重
- 屏幕适配(C3)
- settimeout中的函数this指向window
- 新词发现及Java和spark实现
- 【TensorFlow 官网 可以直接访问】让中国开发者更容易地使用TensorFlow打造人工智能应用
- Android ConstraintLayout属性详解
- 逻辑回归及其分析
- Asp.Net Core-项目结构
- 分布式系统事务一致性解决方案
- 史上最强的Vim 配置文件(原版+中文改进版)
- 拖拽(可以封装成指令的形式 angular )