这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
一个 WebAssembly.Instance 对象是有状态的, 是WebAssembly.Module 的一个可执行实例. 实例包含所有的 WebAssembly 导出函数 ,允许从JavaScript 调用 WebAssembly 代码.
WebAssembly.Instance() 构造函数以同步方式实例化一个WebAssembly.Module 对象. 然而, 通常获取实例的方法是通过异步函数WebAssembly.instantiate() .
重要: 因为大型模块的实例化比较昂贵, 开发人员应该只在同步实例化是必须时,才使用Instance(); 绝大多数情况应该使用异步方法WebAssembly.instantiate() .
var myInstance = new WebAssembly.Instance(module, importObject);
WebAssembly.Module 对象.实例, 比如函数或 WebAssembly.Memory 对象. There must be one matching property for each declared import of module 否则抛出 WebAssembly.LinkError 异常.Instance 实例化所有的 Instance 实例继承自Instance() 属性对象— 修改它会影响所有的Instance 实例.
Instance.prototype.constructorWebAssembly.Instance() constructor.Instance.prototype.exports Read only None.
| 规格 | 状态 | 描述 |
|---|---|---|
| WebAssembly JavaScript Interface Instance |
Working Draft | Initial draft definition. |
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | 57 | 15[2] | 52 (52)[1] | 未实现 | 44 | 11 |
| Feature | Chrome for Android | Android Webview | Edge Mobile | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | 57 | 57 | 未实现 | 52.0 (52)[1] | 未实现 | 未实现 | 11 |
[1] WebAssembly is enabled in Firefox 52+, although disabled in the Firefox 52 Extended Support Release (ESR.)
[2] Currently supported behind the “Experimental JavaScript Features” flag. See this blog post for more details.