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. UML快速理解

    在团队协作过程中最常见的就是开会.开会最常用的就是图,而图中最常见的就是流程图.时序图.类图,这三个图可以清楚的描述你想解释的内容.学好类图不仅仅能帮助自己更清楚的梳理业务,还能提高开会效率. 上图是 ...

  2. thinkphp 项目不能直接域名访问 而要加index.php 才能访问

    一.apache 服务器配置问题 vim /usr/local/apache2/conf/httpd.conf 在ifModule这里加入index.php <IfModule dir_modu ...

  3. springCloud 服务提供者应返回的统一的数据格式

    package com.zledu.commonentity.entity; import lombok.AllArgsConstructor;import lombok.Data; import j ...

  4. springboot-启动一段时间图片不能上传

    问题:[B2B]后台服务.PC服务.APP服务.仓储服务,启动一段时间图片不能上传. 原因:/tmp下以tomcat开头的目录被清理了. 处理方案:1.找到涉及服务器 注:后台服务.PC服务.APP服 ...

  5. NIO编程之多客户端聊天系统

    1. 服务端 import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; im ...

  6. Python3解leetcode Average of Levels in Binary Tree

    问题描述: Given a non-empty binary tree, return the average value of the nodes on each level in the form ...

  7. 最最简单的spring mvc + Maven项目

    首先配置pom文件,只需要引用三个jar包文件即可: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...

  8. 一种算法的实现,几个相同大小的div组合在一起,判断是不是矩形

  9. vue实现动态显示与隐藏底部导航的方法分析

    本文实例讲述了vue实现动态显示与隐藏底部导航的方法.分享给大家供大家参考,具体如下: 在日常项目中,总有几个页面是要用到底部导航的,总有那么些个页面,是不需要底部导航的,这里列举一下页面底部导航的显 ...

  10. zookeeper分布式锁用法

    package com.example.demo3.zk; import lombok.extern.slf4j.Slf4j; import org.apache.storm.shade.org.ap ...