aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/javascript/reference/operators/function/index.html
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 14:45:12 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 14:45:12 +0100
commitcb9e359a51c3249d8f5157db69d43fd413ddeda6 (patch)
treeae3040d626c3b5717da5bda2af9f0a9ff9bd389f /files/ca/web/javascript/reference/operators/function/index.html
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.tar.gz
translated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.tar.bz2
translated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.zip
unslug ca: move
Diffstat (limited to 'files/ca/web/javascript/reference/operators/function/index.html')
-rw-r--r--files/ca/web/javascript/reference/operators/function/index.html146
1 files changed, 146 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/operators/function/index.html b/files/ca/web/javascript/reference/operators/function/index.html
new file mode 100644
index 0000000000..0908f591b6
--- /dev/null
+++ b/files/ca/web/javascript/reference/operators/function/index.html
@@ -0,0 +1,146 @@
+---
+title: function expression
+slug: Web/JavaScript/Referencia/Operadors/function
+translation_of: Web/JavaScript/Reference/Operators/function
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<p>La paraula clau <strong><code>function</code></strong> es pot utilitzar per definir una funció dins d'una expressió.</p>
+
+<h2 id="Sintaxi">Sintaxi</h2>
+
+<pre class="syntaxbox">function [<em>nom</em>]([<em>paràm1</em>[, <em>paràm2[</em>, ..., <em>paràmN</em>]]]) {
+ <em>sentències</em>
+}</pre>
+
+<h3 id="Paràmetres">Paràmetres</h3>
+
+<dl>
+ <dt><code>nom</code></dt>
+ <dd>El nom de la funció. Es pot ometre, i en aquest cas la funció seria <em>anònima</em>. El nom és només local pel cos de la funció.</dd>
+ <dt><code>paràmN</code></dt>
+ <dd>El nom d'un argument que es passa a la funció.</dd>
+ <dt><code>sentències</code></dt>
+ <dd>Les sentències que constitueixen el cos de la funció.</dd>
+</dl>
+
+<h2 id="Descripció">Descripció</h2>
+
+<p>Una expressió d'una funció és molt semblant i té gairebé la mateixa sintaxi que una sentència d'una funció (<a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function sentència d'una funció</a> per més detalls). La principal diferència entre l'expressió d'una funció i una sentèndia d'una expressió és el <em>nom de la functió,</em> el qual es pot ometre en expressions de funcions per tal de crear funcions <em>anònimes</em>. Una expressió d'una funció es pot utilitzar com a un <strong>IIFE </strong>(<em>Immediately Invoked Function Expression</em>) que s'executa un cop s'ha definit. Vegeu també el capítol sobre <a href="/en-US/docs/Web/JavaScript/Reference/Functions">funcions</a> per més informació.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<p>L'exemple següent defineix una funció sense nom i l'assigna a <code>x</code>. La funció retorna el quadrat del seu argument:</p>
+
+<pre class="brush: js">var x = function(y) {
+ return y * y;
+};
+</pre>
+
+<h3 id="Expressió_d'una_funció_amb_nom">Expressió d'una funció amb nom</h3>
+
+<p>Si vols fer referència a la funció actual dins del cos de la funció, necessitaràs crear una expressió d'una funció amb nom. Aquest nom és llavors només local pel cos de la funció (àmbit). AIxò també evita utilitzar la propietat no estàndard <code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee">arguments.callee.</a></code></p>
+
+<pre class="brush: js">var math = {
+ 'factorial': function factorial(n) {
+ if (n &lt;= 1)
+ return 1;
+ return n * factorial(n - 1);
+ }
+};
+</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('ESDraft', '#sec-function-definitions', 'Function definitions')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-13', 'Function definition')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3', '#sec-13', 'Function definition')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Definició inicial. Implementat en JavaScript 1.5.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<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>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</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>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Vegeu_també">Vegeu també</h2>
+
+<ul>
+ <li>{{jsxref("Functions_and_function_scope", "Functions and function scope")}}</li>
+ <li>{{jsxref("Function")}}</li>
+ <li>{{jsxref("Statements/function", "function statement")}}</li>
+ <li>{{jsxref("Statements/function*", "function* statement")}}</li>
+ <li>{{jsxref("Operators/function*", "function* expression")}}</li>
+ <li>{{jsxref("GeneratorFunction")}}</li>
+</ul>