这篇翻译不完整。请帮忙从英语翻译这篇文章

selfWorkerGlobalScope 的只读属性,它指向 WorkerGlobalScope 自身。通常情况下,它是如 DedicatedWorkerGlobalScopeSharedWorkerGlobalScope, 或 ServiceWorkerGlobalScope 类型的 scope 。

语法

var selfRef = self;

当前 worker 的全局 scope (值取决于你创建的 worker 类型)。

示例

在 worker 中运行这行代码:

console.log(self);

console 中会输出当前 worker 的全局 scope,如下所示:

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.

这会列出当前 worker scope 上完整的属性列表,在需要检测某个属性是否可用时非常有用。 详细列表也可查阅 Functions and classes available to Web Workers.

规范

Specification Status Comment
HTML Living Standard
self
Living Standard  

兼容性

 

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 4Edge ? Firefox Full support 3.5IE Full support YesOpera Full support 11.5Safari Full support 4WebView Android ? Chrome Android Full support 40Edge Mobile ? Firefox Android Full support 34Opera Android Full support YesSafari iOS Full support 5.1Samsung Internet Android Full support 4.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

 

参见

WorkerGlobalScope

文档标签和贡献者

此页面的贡献者: librajt
最后编辑者: librajt,