this keyword is outputing different outputs in same object why?

13 views Asked by At

i learned that this keyword inside an object method this refers to the object it self but when it tried it not why,

when i tried that in arrow function syntax this keyword referred to the object it self

and when i tried that in normal function syntax this keyword referred to window object

i expected same output which is the user object



let user = {

  
    method1 :function (){ return this},
    method2 :()=> this,

    };

    console.log(user.method1()); // here this returned user object
    console.log(user.method2());// here this returned window object

how that is done and why ?

0

There are 0 answers