2018-06-22-矢印関数

1510 ワード




  
  06_ 



    
    




  let fun = function () {
       console.log('fun()');
   };
   fun();
   // , 
   let fun1 = () => console.log('fun1()');
    fun1();
   console.log(fun1());
    // , 
    let fun2 = x => x;
    console.log(fun2(5));
    // 
    let fun3 = (x, y) => x + y;
    console.log(fun3(25, 39));//64

    // 
    let fun4 = (x, y) => {
        console.log(x, y);
        return x + y;
    };
    console.log(fun4(34, 48));//82

    setTimeout(() => {
        console.log(this);
    },1000)

   let btn = document.getElementById('btn');
   // 
   btn.onclick = function () {
       console.log(this);//btn
   };
   // 
   let btn2 = document.getElementById('btn2');

    let obj = {
        name : 'kobe',
        age : 39,
        getName : () => {
            btn2.onclick = () => {
                console.log(this);//obj
            };
        }
    };
    obj.getName();


 function Person() {
     this.obj = {
         showThis : () => {
             console.log(this);
         }
     }
 }
    let fun5 = new Person();
    fun5.obj.showThis();