The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code. This function has two overloads:
- The primary overload takes the WebAssembly binary code, in the form of a typed array or
ArrayBuffer, and performs both compilation and instantiation in one step. The returnedPromiseresolves to both a compiledWebAssembly.Moduleand its firstWebAssembly.Instance. - The secondary overload takes an already-compiled
WebAssembly.Moduleand returns aPromisethat resolves to anInstanceof thatModule. This overload is useful if theModulehas already been compiled.
Warning: This method is not the most efficient way of fetching and instantiating wasm modules. If at all possible, you should use the newer WebAssembly.instantiateStreaming() method instead, which fetches, compiles, and instantiates a module all in one step, directly from the raw bytecode, so doesn't require conversion to an ArrayBuffer.