1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <!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>
- <ul>
- <li>aa1</li>
- <li>aa2</li>
- <li>aa3</li>
- <li>aa4</li>
- <li>aa5</li>
- <li>aa6</li>
- <li>aa7</li>
- </ul>
- <script>
- // function fn1() {
- // console.log(this);
- // return 1;
- // }
- // console.log(fn1());
- // 箭头函数格式
- // let fn2 = () => {
- // console.log("@22",this);
- // }
- // fn2()
- // var arr = document.getElementsByTagName("li");
- // // var arr = [1,2,3,4,5,6,7];
- // console.log(arr.length)
- // for(var i = 0; i < arr.length; i++) {
- // // console.log(arr[i])
- // // arr[i].onclick = function() {
- // // console.log(this)
- // // }
- // arr[i].onclick =function(){
- // console.log(this,'父级')
- // setTimeout(() => {
- // console.log(this)
- // },1000)
- // }
- // }
- // function fn2() {
- // console.log(arguments)
- // }
- // let fn2 = (...rest) => {
- // // console.log(...rest)
- // }
- // fn2(4,5,6,7,8);
- // let fn3 = ()=>{
- // "哈哈哈哈"
- // }
- // fn3()
- // function fn4() {
- // console.log(this);
- // }
- // new fn4();
- let fn5 = () => {
- console.log(this);
- };
- new fn5();
- /**
- * 箭头函数特点
- * 1.并没有this 如使用this 则this指向的当前父级的this指向
- * 2.不支持使用arguments 支持使用rest
- * 3.箭头函数 返回值不用return
- * 4.箭头函数没有构造函数 不能使用new
- */
- </script>
- </body>
- </html>
|