WorkerGlobalScope
接口的importScripts()
方法将一个或多个脚本同步导入到工作者的作用域中。
句法
self.importScripts('foo.js'); // one self.importScripts('foo.js', 'bar.js', ...); // multi
参数
DOMString
对象的一个逗号分隔列表,表示要导入的脚本。
返回值
None.
例子
如果您在一个名为foo.js的单独脚本中编写了一些您想在worker.js中使用的功能,则可以使用以下行导入它:
importScripts('foo.js');
importScripts()
和 self.importScripts()
实际上是等效的 — 都表示从工作者的内部范围内调用的 importScripts()
。
规范
Specification | Status | Comment |
---|---|---|
HTML Living Standard importScripts() |
Living Standard | No change from Unknown. |
Unknown importScripts() |
Unknown | Initial definition. |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
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 |
也可以看看
WorkerGlobalScope
- https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Using_web_workers