一、普通函数中的this:
-
this总是代表它的直接调用者, 例如 obj.function ,那么function中的this就是obj;
在默认情况(非严格模式下,未使用 ‘use strict’),没找到直接调用者,则this指的是 window;
在严格模式下,没有直接调用者的函数中的this是 undefined;
使用call,apply,bind(ES5新增)绑定的,this指的是 绑定的对象。
二、箭头函数中的this:
1.箭头函数会捕获其所在上下文的 this 值,作为自己的 this 值,自己本身并没有this值;
2.箭头函数的this永远指向其上下文的this,任何方法都改变不了其指向,如call(), bind(), apply()。
三、call、bind、apply的区别
var name = '老王', age = 17
var obj = {
name: "苦主",
Age: this.age,
myFun: function () {
console.log(`${
this.name}年龄${
this.age}