Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

WorkerGlobalScope.self

The self read-only property of the WorkerGlobalScope interface returns a reference to the WorkerGlobalScope itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScopeSharedWorkerGlobalScope, or ServiceWorkerGlobalScope.

Syntax

var selfRef = self;

Value

A global scope object (differs depending on the type of worker you are dealing with, as indicated above).

Example

If you called

console.log(self);

inside a worker, you will get a worker global scope of the same type as that worker object written to the console — something like the following:

DedicatedWorkerGlobalScope {
undefined: undefined, Infinity: Infinity, Math: MathConstructor, NaN: NaN, Intl: Object…}
    Infinity: Infinity
    Array: function Array() { [native code] }
      arguments: null
      caller: null
      isArray: function isArray() { [native code] }
      length: 1
      name: "Array"
      observe: function observe() { [native code] }
      prototype: Array[0]
      unobserve: function unobserve() { [native code] }
      __proto__: function Empty() {}
      <function scope>
    ArrayBuffer: function ArrayBuffer() { [native code] }
    Blob: function Blob() { [native code] }
    Boolean: function Boolean() { [native code] }
    DataView: function DataView() { [native code] }
    Date: function Date() { [native code] }
    DedicatedWorkerGlobalScope: function DedicatedWorkerGlobalScope() { [native code] }
    Error: function Error() { [native code] }
// etc. etc.

This provides a full list of the objects available to that worker scope, so it is quite a useful test if you want to see whether something is available to your worker or not. We also maintain a list of Functions and classes available to Web Workers.

Note: Firefox has a bug with using console.log inside shared/service workers (see bug 1058644), which may return strange results, but this should be fixed soon.

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'self' in that specification.
Living Standard No change from Web Workers.
Web Workers
The definition of 'self' in that specification.
Candidate Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4 3.5 (1.9.1) (Yes) 11.5 4
Feature Android Chrome for Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 40 1.0 (1.9.1) 1.0.1 (Yes) (Yes) 5.1

See also

WorkerGlobalScope

Document Tags and Contributors

 Contributors to this page: Jeremie, teoli, chrisdavidmills, kscarfone
 Last updated by: Jeremie,