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 exceptionTypeError
, tandis queArray.of
créera un nouvel objetArray
. TypedArray.of
utilise[[Put]]
tandis queArray.of
utilise[[DefineProperty]]
. Ainsi lorsque les arguments sont des objetsProxy
la première méthode appellerahandler.set
pour 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,