A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator below:

Symbol.asyncIterator - JavaScript | MDN

Symbol.asyncIterator

Baseline Widely available

Le symbole connu Symbol.asyncIterator définit l'itérateur asynchrone par défaut d'un objet. Si cette propriété est définie sur un objet, celui-ci est un itérable asynchrone et peut être utilisé avec une boucle for await...of.

Écrivable Non Énumérable Non Configurable Non Description

Le symbole Symbol.asyncIterator est un symbole natif utilisé pour accéder à la méthode @@asyncIterator d'un objet. Pour qu'un objet soit un itérable asynchrone, il doit avoir une clé Symbol.asyncIterator.

Exemples Itérable asynchrone personnalisé

Il est possible de définir son propre itérable en définissant la propriété [Symbol.asyncIterator] d'un objet :

const myAsyncIterable = new Object();
myAsyncIterable[Symbol.asyncIterator] = async function* () {
  yield "coucou";
  yield "l'itération";
  yield "asynchrone !";
};

(async () => {
  for await (const x of myAsyncIterable) {
    console.log(x);
    // expected output:
    //    "coucou"
    //    "l'itération"
    //    "asynchrone !"
  }
})();
Itérables asynchrones natifs

Il n'existe actuellement pas d'objets JavaScript natifs qui possèdent la clé [Symbol.asyncIterator] par défaut. Toutefois, les flux (Streams) WHATWG pourraient devenir les premiers objets natifs itérables asynchrones.

Spécifications Compatibilité des navigateurs Voir aussi

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4