What does “self” mean in javascript?

前端 未结 5 1853
-上瘾入骨i
-上瘾入骨i 2020-12-02 23:04

I read here that \"self Refers to the current window or form\".

Self does not seem to refer to the current form in this case:

5条回答
  •  时光说笑
    2020-12-02 23:42

    self refers to the global scope - If the context is a window it will refer to window.self, while in case of a non-windowed context it will refer to the global scope of that context (e.g. in service worker code, self refers to the worker global scope).

    self refers to the global scope of a context:

    • window context
    • worker context (support for multiple workers for the same webapp is being worked on).

    https://developer.mozilla.org/en-US/docs/Web/API/Window/self

提交回复
热议问题