WTF in 2017
fetchAndInstantiate('./add.wasm').then(function (instance) {
console.log(`1 + 2 = ${instance.exports.add(1, 2)}`);
});
// fetchAndInstantiate() found in wasm-utils.js
function fetchAndInstantiate(url, importObject) {
return fetch(url).then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, importObject)
).then(results =>
results.instance
);
}
https://webkit.org/demos/webgpu/
<script type="module" src="module.js"></script>
<script type="module">
// or an inline script
import {helperMethod} from './providesHelperMethod.js';
helperMethod();
</script>
// providesHelperMethod.js
export function helperMethod() {
console.info(`I'm helping!`);
}