WebAssembly.Instance.prototype.exports
WebAssembly.Instance 对象的 exports 只读属性返回一个对象,该对象包含从 WebAssembly 模块实例导出的所有函数作为其成员,以便 JavaScript 可以访问和使用它们。
示例
使用 exports
使用 fetch 获取一些 WebAssembly 字节码后,我们使用 WebAssembly.instantiateStreaming() 函数来编译和实例化模块,在此过程中将 JavaScript 函数导入到 WebAssembly 模块中。然后,我们调用 Instance 导出的 导出的 WebAssembly 函数。
js
const importObject = {
my_namespace: {
imported_func(arg) {
console.log(arg);
},
},
};
WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
(obj) => obj.instance.exports.exported_func(),
);
注意:您也可以在 GitHub 上找到此示例,名为 instantiate-streaming.html(也可以 在线查看)。
规范
| 规范 |
|---|
| WebAssembly JavaScript 接口 # dom-instance-exports |
浏览器兼容性
加载中…