pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/de/docs/WebAssembly/Reference/JavaScript_interface/Instance/Instance

="preload" href="?u=http://developer.mozilla.org/static/client/inter-latin.9a3b1bc220d426ef.woff2" as="font" type="font/woff2" crossorigen="anonymous" fetchpriority="low" />

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

WebAssembly.Instance() Konstruktor

Baseline Weitgehend verfügbar

Diese Funktion ist gut etabliert und funktioniert auf vielen Geräten und in vielen Browserversionen. Sie ist seit Oktober 2017 browserübergreifend verfügbar.

Der WebAssembly.Instance() Konstruktor erstellt ein neues Instance-Objekt, das eine zustandsbehaftete, ausführbare Instanz eines WebAssembly.Module ist.

Warnung: Da die Instanziierung großer Module kostspielig sein kann, sollten Entwickler den Instance()-Konstruktor nur dann verwenden, wenn eine synchrone Instanziierung unbedingt erforderlich ist; die asynchrone Methode WebAssembly.instantiateStreaming() sollte in allen anderen Fällen verwendet werden.

Syntax

js
new WebAssembly.Instance(module, importObject)

Parameter

module

Das WebAssembly.Module Objekt, das instanziiert werden soll.

importObject Optional

Ein Objekt, das die Werte enthält, die in die neu erstellte Instance importiert werden sollen, wie Funktionen oder WebAssembly.Memory Objekte. Für jeden deklarierten Import des module muss eine passende Eigenschaft vorhanden sein, andernfalls wird ein WebAssembly.LinkError ausgelöst.

Ausnahmen

Beispiele

Synchrone Instanziierung eines WebAssembly-Moduls

Die WebAssembly.Instance() Konstruktorfunktion kann aufgerufen werden, um ein gegebenes WebAssembly.Module Objekt synchron zu instanziieren, zum Beispiel:

js
const importObject = {
  my_namespace: {
    imported_func(arg) {
      console.log(arg);
    },
  },
};

fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => {
    const mod = new WebAssembly.Module(bytes);
    const instance = new WebAssembly.Instance(mod, importObject);
    instance.exports.exported_func();
  });

Der bevorzugte Weg, um eine Instance zu erhalten, ist jedoch die asynchrone Funktion WebAssembly.instantiateStreaming(), zum Beispiel so:

js
const importObject = {
  my_namespace: {
    imported_func(arg) {
      console.log(arg);
    },
  },
};

WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
  (obj) => obj.instance.exports.exported_func(),
);

Spezifikationen

Spezifikation
WebAssembly JavaScript Interface
# dom-instance-instance

Browser-Kompatibilität

Siehe auch

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy