码迷,mamicode.com
首页 > 其他好文 > 详细

this问题 个人总结

时间:2018-05-27 12:05:38      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:箭头   str   定义   set   this   settime   undefined   out   use   

普通函数中的this:

1. this总是代表它的直接调用者(js的this是执行上下文), 例如 obj.func ,那么func中的this就是obj

2.在默认情况(非严格模式下,未使用 ‘use strict‘),没找到直接调用者,则this指的是 window (约定俗成)

3.在严格模式下,没有直接调用者的函数中的this是 undefined

4.使用call,apply,bind(ES5新增)绑定的,this指的是 绑定的对象

 

箭头函数中的this

箭头函数没有自己的this, 它的this是继承而来; 默认指向在定义它时所处的对象(宿主对象),而非执行时的对象, 箭头函数可以方便地让我们在 setTimeout ,setInterval中方便的使用this

this问题 个人总结

标签:箭头   str   定义   set   this   settime   undefined   out   use   

原文地址:https://www.cnblogs.com/zhongyalong/p/9095187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!