19_修改this指向.html 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. /*
  12. 1.call(修改的this,参数1,参数2)
  13. 2.apply(修改的this,[参数1,参数2])
  14. 3.bind(修改的this,参数1,参数2)()
  15. */
  16. // var person = {
  17. // name:'zs',
  18. // age: 18,
  19. // eat: function(){
  20. // console.log(this)
  21. // }
  22. // }
  23. // person.eat()
  24. var person2 = {
  25. name: 'lisi',
  26. age: 30
  27. }
  28. // person.eat.call(person2)
  29. function xx(x,y){
  30. console.log(this,x,y)
  31. }
  32. xx(1,2)
  33. xx.call(person2,1,2)
  34. // xx.apply(person2,[1,2])
  35. // xx.bind(person2,1,2)()
  36. </script>
  37. </body>
  38. </html>