我应该在 service worker 中使用 self 还是 this ?
Should I use self or this in service worker?
我看到 this
作为共享工作者上下文的用法,但在其他文档中也看到了 self
。
我应该使用哪一个?
self
保证指向 ServiceWorkerGlobalScope in which you can find properties such as clients
, registration
or caches
and a variety of event handlers。另一方面,this
遵循与 JavaScript 环境的其余部分相同的动态绑定规则。记住这一点并不重要,但我的建议是当你想专门引用全局上下文时使用 self
。
我看到 this
作为共享工作者上下文的用法,但在其他文档中也看到了 self
。
我应该使用哪一个?
self
保证指向 ServiceWorkerGlobalScope in which you can find properties such as clients
, registration
or caches
and a variety of event handlers。另一方面,this
遵循与 JavaScript 环境的其余部分相同的动态绑定规则。记住这一点并不重要,但我的建议是当你想专门引用全局上下文时使用 self
。