files/en-us/webassembly/reference/javascript_interface/index.md
The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality.
Unlike most other global objects, WebAssembly is not a constructor (it is not a function object). You can compare it to {{jsxref("Math")}}, which is also a namespace object for mathematical constants and functions, or to {{jsxref("Intl")}} which is the namespace object for internationalization constructors and other language-sensitive functions.
The primary uses for the WebAssembly object are:
WebAssembly.instantiate() function.WebAssembly.Memory()/WebAssembly.Table() constructors.WebAssembly.CompileError()/WebAssembly.LinkError()/WebAssembly.RuntimeError() constructors.WebAssembly.CompileError
WebAssembly.Global
WebAssembly.Module instances. This allows dynamic linking of multiple modules.WebAssembly.Instance
WebAssembly.ModuleWebAssembly.LinkError
WebAssembly.Memory
buffer property is a resizable {{jsxref("ArrayBuffer")}} that holds the raw bytes of memory accessed by a WebAssembly Instance.WebAssembly.Module
WebAssembly.RuntimeError
WebAssembly.Table
WebAssembly.Tag
WebAssembly.Exception
WebAssembly.compile()
WebAssembly.Module from WebAssembly binary code, leaving instantiation as a separate step.WebAssembly.compileStreaming()
WebAssembly.Module directly from a streamed underlying source, leaving instantiation as a separate step.WebAssembly.instantiate()
Module and its first Instance.WebAssembly.instantiateStreaming()
Module and its first Instance.WebAssembly.validate()
true) or not (false).The following example (see our instantiate-streaming.html demo on GitHub, and view it live also) directly streams a Wasm module from an underlying source then compiles and instantiates it, the promise fulfilling with a ResultObject. Because the instantiateStreaming() function accepts a promise for a Response object, you can directly pass it a fetch() call, and it will pass the response into the function when it fulfills.
const importObject = {
my_namespace: { imported_func: (arg) => console.log(arg) },
};
WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
(obj) => obj.instance.exports.exported_func(),
);
The ResultObject's .instance property is then accessed, and the contained exported function invoked.
{{Specifications}}
{{Compat}}