-1
    const obj = {
        name: 'something',
        t: function() {
            console.log(this)
        },
        ta: () => {
            console.log(this)
        }
    }
    const parentObj = {
        name: 'cheeteh',
        obj [https://mobdro.bio/][1] 
    }

parentObj.obj.t() parentObj.obj.ta() https://mobdro.bio/ 

How is parentObj.obj.ta() the global scope and not the parentObj ?

can somebody help me?

[1]:

han14
  • 1
  • 1

1 Answers1

1

In JavaScript, regular functions have their own this context, which refers to the object that called the function.

When parentObj.obj.t() is invoked, this inside the "t" function refers to parentObj.obj, which is the object that called the function.

Therefore, the "t" method will log the parentObj.obj object.

On the other hand, arrow functions do not have their own this context. Instead, they inherit the this value from the surrounding scope, which in this case, is the global scope (window).

Parking Master
  • 551
  • 1
  • 4
  • 20
Ramesh Kumar
  • 455
  • 3
  • 10