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>

 

上一篇:使用Maven搭建SpringMVC项目


下一篇:springMVC中从前台往后台传时间