1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <ul>
- <li>1</li>
- <li>2</li>
- <li>3</li>
- </ul>
- <script>
- /*
- 箭头函数和普通函数的区别
- 普通函数里面this 指向window
- 箭头函数里面this 指向声明时的this(父作用域)
- 箭头函数不能new
- 箭头函数可以使用rest 但是不能使用arguments
- */
- // function fn(){
- // console.log(this)
- // }
- // fn()
- // var fn = ()=>{
- // console.log(111)
- // }
- // fn()
- // var aLi = document.getElementsByTagName('li')
- // for(var i =0;i<aLi.length;i++){
- // aLi[i].onclick = function(){
- // // setTimeout(function(){
- // // console.log(this)
- // // }.bind(this),1000)
- // // console.log(this)
- // setTimeout(()=>{
- // console.log(this)
- // },1000)
- // }
- // }
- // var person = {
- // name:'zs',
- // age: 18,
- // eat:()=>{
- // // console.log(this)
- // // setTimeout(()=>{
- // // console.log(this)
- // // },1000)
- // setTimeout(function(){
- // console.log(this)
- // }.bind(this),1000)
- // }
- // }
- // person.eat()
- /* 箭头函数 不能作为构造函数 不能去New */
- // var person = ((name)=>{
- // this.name = name
- // })
- // var p1 = new person('zs')
- // console.log(p1)
-
- let fn = ()=>{
- // console.log(a,...rest)
- console.log(arguments)
- }
- fn(1,2,3)
- </script>
- </body>
- </html>
|