7_箭头函数.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. <ul>
  11. <li>1</li>
  12. <li>2</li>
  13. <li>3</li>
  14. </ul>
  15. <script>
  16. /*
  17. 箭头函数和普通函数的区别
  18. 普通函数里面this 指向window
  19. 箭头函数里面this 指向声明时的this(父作用域)
  20. 箭头函数不能new
  21. 箭头函数可以使用rest 但是不能使用arguments
  22. */
  23. // function fn(){
  24. // console.log(this)
  25. // }
  26. // fn()
  27. // var fn = ()=>{
  28. // console.log(111)
  29. // }
  30. // fn()
  31. // var aLi = document.getElementsByTagName('li')
  32. // for(var i =0;i<aLi.length;i++){
  33. // aLi[i].onclick = function(){
  34. // // setTimeout(function(){
  35. // // console.log(this)
  36. // // }.bind(this),1000)
  37. // // console.log(this)
  38. // setTimeout(()=>{
  39. // console.log(this)
  40. // },1000)
  41. // }
  42. // }
  43. // var person = {
  44. // name:'zs',
  45. // age: 18,
  46. // eat:()=>{
  47. // // console.log(this)
  48. // // setTimeout(()=>{
  49. // // console.log(this)
  50. // // },1000)
  51. // setTimeout(function(){
  52. // console.log(this)
  53. // }.bind(this),1000)
  54. // }
  55. // }
  56. // person.eat()
  57. /* 箭头函数 不能作为构造函数 不能去New */
  58. // var person = ((name)=>{
  59. // this.name = name
  60. // })
  61. // var p1 = new person('zs')
  62. // console.log(p1)
  63. let fn = ()=>{
  64. // console.log(a,...rest)
  65. console.log(arguments)
  66. }
  67. fn(1,2,3)
  68. </script>
  69. </body>
  70. </html>