From de5c456ebded0e038adbf23db34cc290c8829180 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:49:24 +0100 Subject: unslug pl: move --- .../reference/global_objects/array/of/index.html | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 files/pl/web/javascript/reference/global_objects/array/of/index.html (limited to 'files/pl/web/javascript/reference/global_objects/array/of') diff --git a/files/pl/web/javascript/reference/global_objects/array/of/index.html b/files/pl/web/javascript/reference/global_objects/array/of/index.html new file mode 100644 index 0000000000..74c9974bd0 --- /dev/null +++ b/files/pl/web/javascript/reference/global_objects/array/of/index.html @@ -0,0 +1,92 @@ +--- +title: Array.of() +slug: Web/JavaScript/Referencje/Obiekty/Array/of +translation_of: Web/JavaScript/Reference/Global_Objects/Array/of +--- +
{{JSRef}}
+ +

Metoda Array.of() tworzy nową instancję obiektu Array, która zawiera w sobie wszystkie argumenty przekazane do funkcji, niezależnie od ich liczby i typu.

+ +

Różnica pomiędzy Array.of() i konstruktorem Array polega na różnej interpretacji argumentów - Array.of(7) tworzy nową tablicę z jednym elementem(7), gdzie Array(7) tworzy nową tablicę z właściwością length ustawioną na 7 (Notatka: Oznacza to tablicę z 7 wolnymi miejscami, nie miejscami z wartościami undefined).

+ +
Array.of(7);       // [7]
+Array.of(1, 2, 3); // [1, 2, 3]
+
+Array(7);          // [ , , , , , , ]
+Array(1, 2, 3);    // [1, 2, 3]
+
+ +

Składnia

+ +
Array.of(element0[, element1[, ...[, elementN]]])
+ +

Parametry

+ +
+
elementN
+
Elementy, które tworzą tablicę.
+
+ +

Wartość zwracana

+ +

Nowa instancja obiektu {{jsxref("Array")}}.

+ +

Opis

+ +

Ta funkcja jest częścią standardu ECMAScript 2015. Po więcej informacji zobacz Array.of and Array.from proposal i Array.of polyfill.

+ +

Przykłady

+ +
Array.of(1);         // [1]
+Array.of(1, 2, 3);   // [1, 2, 3]
+Array.of(undefined); // [undefined]
+
+ +

Polyfill

+ +

Uruchomienie tego kodu przed innym stworzy Array.of() nawet jeśli nie jest ona dostępna natywnie.

+ +
if (!Array.of) {
+  Array.of = function() {
+    return Array.prototype.slice.call(arguments);
+  };
+}
+
+ +

Specyfikacje

+ + + + + + + + + + + + + + + + + + + +
SpecyfikacjaStatusKomentarz
{{SpecName('ES2015', '#sec-array.of', 'Array.of')}}{{Spec2('ES2015')}}Początkowa definicja.
{{SpecName('ESDraft', '#sec-array.of', 'Array.of')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ +
+ + +

{{Compat("javascript.builtins.Array.of")}}

+
+ +

Zobacz także

+ + -- cgit v1.2.3-54-g00ecf