Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

TypedArray.of()

La méthode TypedArray.of() crée un nouvel objet TypedArray avec un nombre variable d'arguments. Cette méthode est similaire à Array.of().

Syntaxe

TypedArray.of(élément0[, élément1[, ...[, élémentN]]])

où TypedArray est l'un de :

Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array

Paramètres

élémentN
Les éléments avec lesquels on souhaite construire le nouveau tableau typé.

Valeur de retour

Une nouvelle instance de TypedArray.

Description

Il existe de légères différences entre Array.of() et TypedArray.of() :

  • Si la valeur de this passée à TypedArray.of n'est pas un constructeur, TypedArray.of lèvera une exception TypeError, tandis que Array.of créera un nouvel objet Array.
  • TypedArray.of utilise [[Put]] tandis que Array.of utilise [[DefineProperty]]. Ainsi lorsque les arguments sont des objets Proxy la première méthode appellera handler.set pour créer les nouveaux éléments et la seconde appellera handler.defineProperty.

Exemples

Uint8Array.of(1);            // Uint8Array [ 1 ]
Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]
Float32Array.of(1, 2, 3);    // Float32Array [ 1, 2, 3 ]
Int16Array.of(undefined);    // IntArray [ 0 ]

Spécifications

Spécification État Commentaires
ECMAScript 2015 (6th Edition, ECMA-262)
La définition de '%TypedArray%.of' dans cette spécification.
Standard Définition initiale au sein d'un standard ECMA.
ECMAScript 2017 Draft (ECMA-262)
La définition de '%TypedArray%.of' dans cette spécification.
Projet  

Compatibilité des navigateurs

Fonctionnalité Chrome Firefox (Gecko) Internet Explorer Opera Safari
Support simple 45.0 38 (38) Pas de support Pas de support Pas de support
Fonctionnalité Android Chrome pour Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Support simple Pas de support Pas de support 38.0 (38) Pas de support Pas de support Pas de support

Voir aussi

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : SphinxKnight, cdr
 Dernière mise à jour par : SphinxKnight,