12_箭头函数.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <div id="box">hello world</div>
  10. <script>
  11. // function foo(){
  12. // console.log("hello");
  13. // }
  14. // let fn = function(){
  15. // console.log("hello");
  16. // }
  17. // // 箭头函数
  18. // let fn2 = () => {};
  19. // let fn = (a) => {
  20. // console.log(a);
  21. // console.log("hello world");
  22. // }
  23. // fn(1);
  24. // arguments 是一个类数组对象
  25. // 里面容纳是所有的参数
  26. // function fn(){
  27. // console.log(arguments)
  28. // console.log(arguments[0]);
  29. // console.log(arguments[1]);
  30. // }
  31. // fn(1,'a');
  32. // // 箭头函数 没有 arguments 这个对象
  33. // let fn = (...arg) => {
  34. // // console.log(arguments);
  35. // console.log(arg);
  36. // }
  37. // fn(1,"a");
  38. // 箭头函数 没有 this这个对象
  39. // let oBox = document.querySelector("#box");
  40. // oBox.onclick = function(){
  41. // console.log(this);
  42. // }
  43. // oBox.onclick = () => {
  44. // console.log(this);
  45. // }
  46. // console.log(this);
  47. // let fun = () => {
  48. // console.log("hello world");
  49. // }
  50. // let fun = () => {
  51. // return "hello";
  52. // }
  53. // 如果箭头函数没有{} 表示直接 rentur 后面第一行代码
  54. let fun = () => "hello";
  55. let str = fun();
  56. console.log(str);
  57. </script>
  58. </body>
  59. </html>