一个 WebAssembly.Instance 对象是有状态的, 是WebAssembly.Module 的一个可执行实例.  实例包含所有的 WebAssembly 导出函数 ,允许从JavaScript 调用 WebAssembly 代码.

WebAssembly.Instance() 构造函数以同步方式实例化一个WebAssembly.instantiate() .


重要: 因为大型模块的实例化比较昂贵, 开发人员应该只在同步实例化是必须时,才使用Instance(); 绝大多数情况应该使用异步方法WebAssembly.instantiate() .

var myInstance = new WebAssembly.Instance(module, importObject);


要被实例化的 WebAssembly.Module 对象.
importObject 可选
一个包含值的对象,导入到新创建的 实例, 比如函数或 WebAssembly.Memory 对象. There must be one matching property for each declared import of module 否则抛出 WebAssembly.LinkError 异常.

Instance 实例化

所有的 Instance 实例继承自Instance() 属性对象— 修改它会影响所有的Instance 实例.

Instance 属性

Returns the function that created this object's instance. By default this is the WebAssembly.Instance() constructor.
Instance.prototype.exports Read only
Returns an object containing as its members all the functions exported from the WebAssembly module instance, to allow them to be accessed and used by JavaScript.

Instance 方法



规格 状态 描述
WebAssembly JavaScript Interface
Working Draft Initial draft 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 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.

See also