In Javascript, why is the “this” operator inconsistent?

后端 未结 8 1773
挽巷
挽巷 2020-11-22 15:04

In JavaScript, the \"this\" operator can refer to different things under different scenarios.

Typically in a method within a JavaScript \"object\", it refers to the

8条回答
  •  渐次进展
    2020-11-22 16:05

    I believe this may be due to how the idea of [closures](http://en.wikipedia.org/wiki/Closure_(computer_science) work in Javascript.

    I am just getting to grips with closures myself. Have a read of the linked wikipedia article.

    Here's another article with more information.

    Anyone out there able to confirm this?

提交回复
热议问题