aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/javascript/reference/global_objects/array/of
diff options
context:
space:
mode:
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/array/of')
-rw-r--r--files/ca/web/javascript/reference/global_objects/array/of/index.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/array/of/index.html b/files/ca/web/javascript/reference/global_objects/array/of/index.html
new file mode 100644
index 0000000000..efe2d96abd
--- /dev/null
+++ b/files/ca/web/javascript/reference/global_objects/array/of/index.html
@@ -0,0 +1,120 @@
+---
+title: Array.of()
+slug: Web/JavaScript/Referencia/Objectes_globals/Array/of
+translation_of: Web/JavaScript/Reference/Global_Objects/Array/of
+---
+<div>{{JSRef}}</div>
+
+<p>El mètode <code><strong>Array.of()</strong></code> crea una nova instància <code>Array</code> amb un nombre variable d'arguments, sense tenir en compte el nombre o el tipus d'arguments.</p>
+
+<p>La diferència entre <code><strong>Array.of()</strong></code> i el constructor <code><strong>Array</strong></code> es troba en el maneig dels arguments sencers: <code><strong>Array.of(42)</strong></code> crea un array amb un sol element, <code>42</code>, mentre que <code><strong>Array(42)</strong></code> crea un array amb 42 elements, Cadascun dels quals és <code>undefined</code>.</p>
+
+<h2 id="Sintaxi">Sintaxi</h2>
+
+<pre class="syntaxbox"><code>Array.of(<var>element0</var>[, <var>element1</var>[, ...[, <var>elementN</var>]]])</code></pre>
+
+<h3 id="Paràmetres">Paràmetres</h3>
+
+<dl>
+ <dt><code>element<em>N</em></code></dt>
+ <dd>Elements a partir dels quals es crea l'array.</dd>
+</dl>
+
+<h2 id="Descripció">Descripció</h2>
+
+<p>Aquesta funció forma part del ECMAScript 6 estàndard. Per més informació vegeu <a href="https://gist.github.com/rwaldron/1074126">proposta de l'<code>Array.of</code> i <code>Array.from</code> </a> i <a href="https://gist.github.com/rwaldron/3186576"><code>Array.of</code> polyfill</a>.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<pre class="brush: js">Array.of(1); // [1]
+Array.of(1, 2, 3); // [1, 2, 3]
+Array.of(undefined); // [undefined]
+</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>Executar el codi següent abans que cap altre codi crearà <code>Array.of()</code> en cas que no es trobi disponible de forma nativa.</p>
+
+<pre class="brush: js">if (!Array.of) {
+ Array.of = function() {
+ return Array.prototype.slice.call(arguments);
+ };
+}
+</pre>
+
+<h2 id="Especificacions">Especificacions</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificació</th>
+ <th scope="col">Estat</th>
+ <th scope="col">Comentaris</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-array.of', 'Array.of')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Definició inicial.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Característica</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Suport bàsic</td>
+ <td>{{CompatChrome(45)}}</td>
+ <td>{{CompatGeckoDesktop("25")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Característica</th>
+ <th>Android</th>
+ <th>Chrome per Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Suport bàsic</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(39)}}</td>
+ <td>{{CompatGeckoMobile("25")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Vegeu_també">Vegeu també</h2>
+
+<ul>
+ <li>{{jsxref("Array")}}</li>
+ <li>{{jsxref("Array.from()")}}</li>
+ <li>{{jsxref("TypedArray.of()")}}</li>
+</ul>