this指向bind、call、apply

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ll</title>
</head>
<body>
<script>
  var aaa = function (x, y) {
    console.log(this)
    console.log(x, y)
  }
  var thisObj = {data: 111}

  aaa(1, 2)
  // this -> window
  // 1,2

  // 1、bind
  aaa.bind(thisObj)(3, 4)
  // this -> thisObj
  // 3,4

  // 2、call
  aaa.call(thisObj, 5, 6)
  // this -> thisObj
  // 5,6

  // 3、apply
  aaa.apply(thisObj, [7, 8])
  // this -> thisObj
  // 7,8
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/linding/p/14480316.html