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
thispassée àTypedArray.ofn'est pas un constructeur,TypedArray.oflèvera une exceptionTypeError, tandis queArray.ofcréera un nouvel objetArray. TypedArray.ofutilise[[Put]]tandis queArray.ofutilise[[DefineProperty]]. Ainsi lorsque les arguments sont des objetsProxyla première méthode appellerahandler.setpour créer les nouveaux éléments et la seconde appellerahandler.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
Étiquettes :
Contributeurs à cette page :
SphinxKnight,
cdr
Dernière mise à jour par :
SphinxKnight,