const test ={
id:2,
a:function(){
var a_this=this;
setTimeout(function(){
console.log('a:',this,a_this)
})
},
a1:()=>{
var a1_this=this;
setTimeout(function(){
console.log('a1:',this,a1_this)
})
},
a11:()=>{
var a11_this=this;
setTimeout(()=>{
console.log('a11:',this,a11_this)
})
},
aa:function(){
var aa_this=this;
console.log('aa:',this,aa_this)
},
aa1:()=>{
var aa1_this=this;
console.log('aa1:',this,aa1_this)
}

}
test.a();
test.a1();
test.a11();
test.aa();
test.aa1();

const tests={
id:'tests',
a_tests:{
id:'a_tests',
a_tests_child:function(){
var a_tests_this = this;
console.log('a_tests_child:',this,a_tests_this)
},
a1_tests_child: () => {
var a1_tests_this = this;
console.log('a1_tests_child:',this,a1_tests_this)
},
a11_tests_child:{
a1111_tests_child:function(){
var a1111_tests_this = this;
console.log('a1111_tests_child:',this,a1111_tests_this)
},

a11112_tests_child: () => {
var a11112_tests_this = this;
console.log('a11112_tests_child:',this,a11112_tests_this)
}

}
}
}
tests.a_tests.a_tests_child();
tests.a_tests.a1_tests_child();
tests.a_tests.a11_tests_child.a1111_tests_child();
tests.a_tests.a11_tests_child.a11112_tests_child();

无论内部嵌套有多深,箭头函数this总是指向了window全局对象

es5和es6中的this指向问题的更多相关文章

  1. ES5和ES6中的继承

    看到一篇写的非常好的关于js继承的文章,其中对构造函数.原型.实例之间的关系的描述十分透彻,故转载作者文章以随时学习,并供大家共同进步! ES5 ES5中的继承,看图: function Super( ...

  2. ES5和ES6中对于继承的实现方法

    在ES5继承的实现非常有趣的,由于没有传统面向对象类的概念,Javascript利用原型链的特性来实现继承,这其中有很多的属性指向和需要注意的地方. 原型链的特点和实现已经在之前的一篇整理说过了,就是 ...

  3. ES5和ES6中的继承 图解

    Javascript中的继承一直是个比较麻烦的问题,prototype.constructor.__proto__在构造函数,实例和原型之间有的 复杂的关系,不仔细捋下很难记得牢固.ES6中又新增了c ...

  4. ES5与ES6中的继承

    ES5继承在ES5中没有类的概念,所以一般都是基于原型链继承,具体的继承方法有以下几种: 父类: function Father (name) { this.name = name || 'sam' ...

  5. 在ES5实现ES6中的Object.is方法

    ES6中对象的扩展里面添加了一个Object.is方法,用于比较两个值是否严格相等.内部计算与 === 行为基本一致.那么我们怎么在不支持这个方法的ES5中实现呢? 首先我们需要搞清楚两点,1:Obj ...

  6. ES5和ES6中关于import & export的书写方式的区别

    ES6中输出变量的写法 情景1:单个变量 输出 export const less = 'less' 引用 import {less} from '../index.js' 情景2:多个变量 输出: ...

  7. 浅谈es5和es6中的继承

    首先给大家介绍下在es5中构造函数的继承 function A(){ 2 //构造函数A 3 this.name="我是A函数"; 4 } 5 6 A.prototype={ 7 ...

  8. es5和es6中查找数组中的元素

    let array = [1,2,3,4,5] //es5 let find = array.filter(function (item){ return item %2 === 0//返回满足条件的 ...

  9. es5和es6中如何处理不确定参数

    场景:求出不定参数的总数和 //利用arguments function sum () { let num = 0 //Array.prototype.forEach.call(arguments,f ...

随机推荐

  1. SQL中exists和in的区别

  2. 获取kingeditor编辑器内容

    //初始化编辑器 var editorMini = KindEditor.create('.editor-mini',{ width : '70%', height : '250px', resize ...

  3. 026:if标签使用详解

    if标签使用详解: if 标签: if 标签相当于 Python 中的 if 语句,有 elif 和 else 相对应,但是所有的标签都需要用标签符号  {%  %}  进行包裹. if 标签中可以使 ...

  4. re模块的高级使用

    主要有四个方法: search : 从字符串的任意位置开始检索,首次匹配即结束 findall : 全部匹配 sub : 将正则匹配结果进行替换 split : 根据正则匹配结果将字符串进行切分,然后 ...

  5. 未能加载文件或程序集 ICSharpCode.SharpZipLib

    Ui调用Webservice ,Webservice调用Bl BL中明明有那个dll文件 后来发现是webservice里面没有 在附加调试的时候,断点在bl层中

  6. win7系统安装sql2000数据库时没有反应,不出来安装界面?

    今天一个客户反馈软件连不上数据库,经检查发现SQL服务启动不了,懒得查原因就把SQL2000卸载了,他们电脑是win7的系统,本来正常来说安装SQL2000数据库是没啥问题的,可是特别奇怪的是,这台w ...

  7. SQL Server性能调优--索引

    序言 索引的概念 索引是什么 数据库中的索引类似于一本书的目录,在一本书中使用目录可以快速找到你想要的信息,而不需要读完全书.在数据库中,数据库程序使用索引可以快速查询到表中的数据,而不必扫描整个表. ...

  8. lightoj1094 - Farthest Nodes in a Tree

    1094 - Farthest Nodes in a Tree   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limi ...

  9. (转)使用windows server2008 创建 Hyper-V虚拟机

    转:https://jingyan.baidu.com/article/7c6fb42833ad4980652c904f.html Hyper-v是微软提供的虚拟机,利用server 2008搭建hy ...

  10. Mac下隐藏或显示文件/文件夹

    命令行操作 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults write com.apple.fi ...