(export...)
Exports an object to JavaScript. You can export many different types of objects. You can only export one object per (export...) S-Expression. You can either add the export S-Expression within the object that is being exported, or create an S-Expression on its own that points to the object being exported.

Syntax

(global... (export propertyName) )
(memory... (export propertyName) )
(func... (export propertyName) )
(table... (export propertyName) )
(export propertyName
  (global $global)
  (memory $memory)
  (func  $function)
  (table $table)
)

Parameters

configProperty
The name of the property that holds the object exported.
$globalOptional
Points to an existing (global...) object that contains all the details relating to the object being exported.
$memoryOptional
Points to an existing (memory...) object that will be exported.
$functionOptional
Points to an existing (func...) object that to be exported.
$tableOptional
Points to an existing (table...) object that is being exported.

Examples

;; Create $add function
(func $add (param $first i32) (param $second i32) (result i32)
  ;; Add first and second parameters together and return result
  local.get $first
  local.get $second
  i32.add
)

;; Export the $add function using the "add" property name
(export "add" $add)
;; Create function and export it (it has no name of its own)
(func (export "add") (param $first i32) (param $second i32) (result i32)
  ;; Add first and second parameters together and return result
  local.get $first
  local.get $second
  i32.add
)
// Load in and create instance of add.wasm file
const wasm = await WebAssembly.instantiateStreaming(fetch('add.wasm'));

// Call the exported WASM add function
const result = wasm.instance.exports.add(42, 101);