7_箭头函数.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // function fn1(){
  17. // }
  18. // var fn = () => {
  19. // console.log(111)
  20. // }
  21. // fn()
  22. /*
  23. 箭头函数和普通函数的区别:
  24. 1.普通函数调用this-> window
  25. 2.箭头函数 指向声明时的this(父作用域的this)
  26. 3.箭头函数 不能作为构造函数 不能new 没有prototype
  27. 4.箭头函数可以使用rest 但是不能使用arguments
  28. 5.
  29. */
  30. // var aLi = document.querySelectorAll('li')
  31. // for (var i = 0; i < aLi.length; i++) {
  32. // aLi[i].onclick = function(){
  33. // // setTimeout(function(){
  34. // // console.log(this)
  35. // // }.bind(this),100)
  36. // setTimeout(()=>{
  37. // console.log(this)
  38. // },1000)
  39. // }
  40. // }
  41. // var person = {
  42. // name: 'zs',
  43. // age: 18,
  44. // eat: function(){
  45. // console.log(this)
  46. // // setTimeout(function(){
  47. // // console.log(this)
  48. // // }.bind(this),1000)
  49. // setTimeout(()=>{
  50. // console.log(this)
  51. // },100)
  52. // }
  53. // }
  54. // person.eat()
  55. /* var person = (name) =>{
  56. this.name = name
  57. }
  58. var p1 = new person('zs')
  59. console.log(p1) */
  60. // var p = () => {
  61. // a = 1
  62. // }
  63. // // const aa = new p()
  64. // // console.log(p)
  65. // function x(){
  66. // b = 2
  67. // }
  68. // console.log(x)
  69. // const bb = new x()
  70. // const fn = ()=>{
  71. // console.log(arguments)
  72. // }
  73. // fn(1,2,3)
  74. // function fn(x, y) {
  75. // return x + y
  76. // }
  77. // console.log(fn(4, 5))
  78. var fn = (x, y) => {
  79. return c = x + y
  80. console.log(c)
  81. }
  82. console.log(fn(1,2))
  83. </script>
  84. </body>
  85. </html>