Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use self or this in service worker?

I have seen usage of this as the shared worker context, but also self in other documentations.

Which one should I use ?

like image 795
Walle Cyril Avatar asked Jun 26 '16 15:06

Walle Cyril


People also ask

What is an example of a service worker?

Examples of personal service positions include: medical assistants and other healthcare support positions, hairdressers, ushers, and transportation attendants. Examples of cleaning service positions include: cleaners, janitors, and porters.

What is the use of service worker?

Service workers are specialized JavaScript assets that act as proxies between web browsers and web servers. They aim to improve reliability by providing offline access, as well as boost page performance.

Does service worker work on HTTP?

To run code using service workers, you'll need to serve your code via HTTPS — Service workers are restricted to running across HTTPS for security reasons.


1 Answers

self is guaranteed to point to the ServiceWorkerGlobalScope in which you can find properties such as clients, registration or caches and a variety of event handlers. In the other hand, this obeys the same rules about dynamic binding as in the rest of the JavaScript environment. It does not matter always you remember this but my advice is to use self when you want to refer the global context specifically.

like image 199
Salva Avatar answered Sep 24 '22 20:09

Salva