1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="box">hello world</div>
- <script>
- // function foo(){
- // console.log("hello");
- // }
- // let fn = function(){
- // console.log("hello");
- // }
- // // 箭头函数
- // let fn2 = () => {};
- // let fn = (a) => {
- // console.log(a);
- // console.log("hello world");
- // }
- // fn(1);
- // arguments 是一个类数组对象
- // 里面容纳是所有的参数
- // function fn(){
- // console.log(arguments)
- // console.log(arguments[0]);
- // console.log(arguments[1]);
- // }
- // fn(1,'a');
- // // 箭头函数 没有 arguments 这个对象
- // let fn = (...arg) => {
- // // console.log(arguments);
- // console.log(arg);
- // }
- // fn(1,"a");
- // 箭头函数 没有 this这个对象
- // let oBox = document.querySelector("#box");
- // oBox.onclick = function(){
- // console.log(this);
- // }
- // oBox.onclick = () => {
- // console.log(this);
- // }
- // console.log(this);
-
- // let fun = () => {
- // console.log("hello world");
- // }
- // let fun = () => {
- // return "hello";
- // }
- // 如果箭头函数没有{} 表示直接 rentur 后面第一行代码
- let fun = () => "hello";
-
- let str = fun();
- console.log(str);
- </script>
- </body>
- </html>
|