diff options
Diffstat (limited to 'files/ca/web/javascript/reference/statements/function/index.html')
-rw-r--r-- | files/ca/web/javascript/reference/statements/function/index.html | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/files/ca/web/javascript/reference/statements/function/index.html b/files/ca/web/javascript/reference/statements/function/index.html deleted file mode 100644 index 207c3b0af8..0000000000 --- a/files/ca/web/javascript/reference/statements/function/index.html +++ /dev/null @@ -1,172 +0,0 @@ ---- -title: function -slug: Web/JavaScript/Reference/Statements/function -translation_of: Web/JavaScript/Reference/Statements/function -original_slug: Web/JavaScript/Referencia/Sentencies/function ---- -<div> -<div>{{jsSidebar("Statements")}}</div> -</div> - -<h2 id="Resum">Resum</h2> - -<p>La <strong>declaració d'una funció</strong> defineix una funció amb uns paràmetres especificats.</p> - -<div class="noinclude"> -<p>També podeu definir funcions fent servir el constructor {{jsxref("Function")}} i un {{jsxref("Operators/function", "function expression")}}.</p> -</div> - -<h2 id="Syntax" name="Syntax">Sintaxi</h2> - -<pre class="syntaxbox">function <em>nom</em>([<em>paràm</em>,[, <em>paràm</em>,[..., <em>paràm</em>]]]) { - [<em>sentències</em>] -} -</pre> - -<dl> - <dt><code>nom</code></dt> - <dd>El nom de la funció.</dd> -</dl> - -<dl> - <dt><code>paràm</code></dt> - <dd>El nom d'un argument que se li passarà a la funció. Una funció pot arribar a tenir fins a 255 arguments.</dd> -</dl> - -<dl> - <dt><code>sentències</code></dt> - <dd>Les sentències que comprenen el cos de la funció.</dd> -</dl> - -<h2 id="Description" name="Description">Descripció</h2> - -<p>Una funció creada amb una declaració d'una funció és un objecte <code>Function</code> i té totes les propietats, mètodes i comportament dels objectes <code>Function</code>. Vegeu {{jsxref("Function")}} per informació detallada sobre funcions.</p> - -<p>Una funció també es pot crear fent servir una expressió (vegeu {{jsxref("Operators/function", "function expression")}}).</p> - -<p>Per defecte, les funcions retornen <code>undefined</code>. Per tal de retornar qualsevol altre valor, la funció ha de tenir una sentència {{jsxref("Statements/return", "return")}} que especifiqui el valor que retorna.</p> - -<h3 id="Funcions_creades_de_forma_condicional">Funcions creades de forma condicional</h3> - -<p>Les funcions poden ser declarades de forma condicional, és a dir, una sentència d'una funció pot estar aniuada dins d'una sentència <code>if</code>. La majoria de navegadors que no siguin Mozilla tractaran aquestes declaracions condicionals com a declaracions incondicionals i crearàn la funció tant si la condició és vertadera o falsa, vegeu <a href="http://kangax.github.io/nfe/#function-statements">aquest article</a> per una visió general. Per tant, no s'haurien de fer servir, per creacions condicionals feu servir expressions de funcions.</p> - -<h3 id="Declarar_les_funcions_abans_de_definir-les_(hosting)">Declarar les funcions abans de definir-les <em>(hosting)</em></h3> - -<p><u>Function declarations in JavaScript are hoisting the function definition</u>. En Javascript es pot ser cridar una funció abans de declarar-la. En anglès existeix un ver:</p> - -<pre class="brush: js">hoisted(); // logs "foo" - -function hoisted() { - console.log("foo"); -} -</pre> - -<p>Vegeu que {{jsxref("Operators/function", "function expressions")}} no estan hoisted:</p> - -<pre class="brush: js">notHoisted(); // TypeError: notHoisted is not a function - -var notHoisted = function() { - console.log("bar"); -}; -</pre> - -<h2 id="Exemples">Exemples</h2> - -<h3 id="Exemple_Fer_servir_function">Exemple: Fer servir <code>function</code></h3> - -<p>El codi següent declara una funció que retorna la quantitat total de vendes, quan se li dóna el nombre d'unitat venudes d' <code>a</code>, <code>b</code>, i <code>c</code>.</p> - -<pre class="brush: js">function calc_sales(units_a, units_b, units_c) { - return units_a*79 + units_b * 129 + units_c * 699; -} -</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>1a edició de ECMAScript.</td> - <td>Estàndard</td> - <td>Definició iniciañ. Implementat en JavaScript 1.0</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-13', 'Function definition')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </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="See_also" name="See_also">Vegeu també</h2> - -<ul> - <li>{{jsxref("Functions_and_function_scope", "Functions and function scope")}}</li> - <li>{{jsxref("Function")}}</li> - <li>{{jsxref("Operators/function", "function expression")}}</li> - <li>{{jsxref("Statements/function*", "function* statement")}}</li> - <li>{{jsxref("Operators/function*", "function* expression")}}</li> - <li>{{jsxref("GeneratorFunction")}}</li> -</ul> |