其他分享
首页 > 其他分享> > this指向-bind、call、apply

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>

 

标签:aaa,log,bind,call,apply,thisObj
来源: https://www.cnblogs.com/linding/p/14480316.html