12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #box {
- width: 200px;
- height: 200px;
- background: aqua;
- }
- </style>
- </head>
- <body>
- <div id="box"></div>
- <script>
- /**
- * 箭头函数
- *xxx = () => {
- * }
- * 1.箭头函数中没有this this指向上级
- * 2.箭头函数中不能使用arguments 可以使用rest
- * 3.箭头函数不用return
- * 4.箭头函数无法使用new
- */
- // box.onclick = () =>{
-
- // }
- // var box = document.getElementById("box");
- // box.onclick = function() {
- // console.log(this,'普通函数')
- // }
- // let a ='';
- // box.onclick = function(){
- // console.log(this,'1')
- // setInterval(()=> {
- // // a ="哈哈";
- // console.log(this,'监听函数')
- // // return a;
- // },1000)
- // }
- // function fn4() {
- // return a = '哈哈'
- // }
- // fn4()
- // console.log(a);
- // function fn1(){
- // console.log(this,'普通函数')
- // }
- // fn1();
- // let fn2 = ()=>{
- // console.log(this,'箭头函数')
- // }
- // fn2()
- let fn3 = (...rest) =>{
- console.log(...rest)
- // console.log(arguments)
- }
- // new
- fn3(1,2,3,4,5,7)
- </script>
- </body>
- </html>
|