0

I see this on Internet:(source: https://www.w3schools.com/js/js_arrow_function.asp)

1.In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever.

2.With arrow functions the this keyword always represents the object that defined the arrow function.

But when I run this code:

var x = {
    value:1,
    get:()=>this//*
}
console.log(x.get())

I see that : arrow function * is defined in obj x. So with clause 2: i think when I run this code the result will be x. But not, the result is Window. I don't know why or what I see is Wrong. Hope guys can help me!!

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
  • [Duplicate](https://google.com/search?q=site%3Astackoverflow.com+js+arrow+function+this+in+object) of [Arrow Function in Object Literal](https://stackoverflow.com/q/36717376/4642212). Please read the more up-to-date and complete documentation at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#arrow_functions_used_as_methods), and see [Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?](https://stackoverflow.com/q/34361379/4642212). – Sebastian Simon Mar 13 '21 at 06:32
  • You just defined `window.x` with `var x = {`. Remember, variables declared in the global scope are a part of the window. – enhzflep Mar 13 '21 at 06:49

0 Answers0