diff options
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/boolean')
4 files changed, 536 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/boolean/index.html b/files/ca/web/javascript/reference/global_objects/boolean/index.html new file mode 100644 index 0000000000..d0a6d6eef7 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/boolean/index.html @@ -0,0 +1,197 @@ +--- +title: Boolean +slug: Web/JavaScript/Reference/Global_Objects/Boolean +translation_of: Web/JavaScript/Reference/Global_Objects/Boolean +original_slug: Web/JavaScript/Referencia/Objectes_globals/Boolean +--- +<div>{{JSRef("Global_Objects", "Boolean")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>L'objecte <strong><code>Boolean</code></strong> és un objecte que embolcalla valors booleans.</p> + +<h2 id="Syntax" name="Syntax">Constructor</h2> + +<pre class="syntaxbox"><code>new Boolean([<var>valors</var>])</code></pre> + +<h3 id="Parameters" name="Parameters">Paràmetres</h3> + +<dl> + <dt><code>valors</code></dt> + <dd>Opcional. El valor inicial de l'objecte <code>Boolean</code>.</dd> +</dl> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>El valor passat com a primer paràmetre es converteix a un valor booleà, en cas necesari. Si és omés o si és <code>0</code>, <code>-0</code>, {{jsxref("Global_Objects/null", "null")}}, <code>false</code>, {{jsxref("Global_Objects/NaN", "NaN")}}, {{jsxref("Global_Objects/undefined", "undefined")}}, o la cadena de caràcters buida (<code>""</code>), l'objecte tindrà el valor inicial <code>false</code>. Tots els altres valors, incloent qualsevol objecte o la cadena de caràcters <code>"false"</code>, crea un objecte amb el valor inicial de <code>true</code>.</p> + +<p>No confoneu els valors <code>Boolean</code> primitius <code>true</code> i <code>false</code> amb els valors <code>true</code> i <code>false</code> de l'objecte <code>Boolean</code>.</p> + +<p>Qualsevol objecte el valor del qual no sigui {{jsxref("Global_Objects/undefined", "undefined")}} o {{jsxref("Global_Objects/null", "null")}}, incloent un objecte de tipus <code>Boolean</code> el valor del qual sigui <code>false</code>, evalua a <code>true</code> quan es passa a una sentència condicional. Per exemple, la condició en la següent sentència {{jsxref("Statements/if...else", "if")}} evalua a <code>true</code>:</p> + +<pre class="brush: js">x = new Boolean(false); +if (x) { + // aquest codi s'executarà +} +</pre> + +<p>Aquest comportament no s'aplica a les primitives de tipus booleà. Per exemple, la condició en la següent sentència {{jsxref("Statements/if...else", "if")}} evalua a <code>false</code>:</p> + +<pre class="brush: js">x = false; +if (x) { + // aquest codi no s'executarà +} +</pre> + +<p>No creeu una instància de <code>Boolean</code> per a convertir un valor no booleà a un valor booleà. En comptes d'això utilitzeu <code>Boolean</code> com una funció per a realitzar aquesta tasca:</p> + +<pre class="brush: js">x = Boolean(expression); // utilitzar preferentment +x = new Boolean(expression); // no ho utilitzeu +</pre> + +<p>Si s'especifica qualsevol objecte, inclòs un objecte <code>Boolean</code> el valor del qual sigui false, com a valor inicial per a un objecte <code>Boolean</code>, el nou objecte <code>Boolean</code> tindrà un valor de <code>true</code>.</p> + +<pre class="brush: js">myFalse = new Boolean(false); // valor inicial false +g = new Boolean(myFalse); // valor inicial true +myString = new String('Hello'); // objecte de tipus String +s = new Boolean(myString); // valor inicial true +</pre> + +<p>No utilitzeu un objecte <code>Boolean</code> quan podríeu utilitzar un valor primitiu booleà.</p> + +<h2 id="Properties" name="Properties">Propietats</h2> + +<dl> + <dt><code>Boolean.length</code></dt> + <dd>La propietat Length retorna el valor de 1.</dd> + <dt>{{jsxref("Boolean.prototype")}}</dt> + <dd>Representa el prototip pel constructor <code>Boolean</code>.</dd> +</dl> + +<p>{{jsOverrides("Function", "Properties", "prototype")}}</p> + +<h2 id="Methods" name="Methods">Mètodes</h2> + +<p>L'objecte <code>Boolean</code> no té mètodes propis. Hereta, però, alguns mètodes a través de la cadena de prototipus:</p> + +<div>{{jsOverrides("Function", "Methods")}}</div> + +<h2 id="Boolean_instances" name="Boolean_instances"><code>Instàncies de Boolean</code></h2> + +<p>Totes les instàncies de <code>Boolean</code> hereten de {{jsxref("Boolean.prototype")}}. Com tots els constructors, el prototipus de l'objecte dicta les propietats i mètodes que heretaran les instàncies.</p> + +<h3 id="Propietats">Propietats</h3> + +<div>{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/Boolean/prototype', 'Properties')}}</div> + +<h3 id="Mètodes">Mètodes</h3> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/prototype', 'Methods')}}</div> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Example:_Creating_Boolean_objects_with_an_initial_value_of_false" name="Example:_Creating_Boolean_objects_with_an_initial_value_of_false">Exemple: Crear objectes <code>Boolean</code> amb un valor inicial de<code> false</code></h3> + +<pre class="brush: js">var bNoParam = new Boolean(); +var bZero = new Boolean(0); +var bNull = new Boolean(null); +var bEmptyString = new Boolean(''); +var bfalse = new Boolean(false); +</pre> + +<h3 id="Example:_Creating_Boolean_objects_with_an_initial_value_of_true" name="Example:_Creating_Boolean_objects_with_an_initial_value_of_true">Exemple: Crear objectes <code>Boolean amb un valor inicial de</code> <code>true</code></h3> + +<pre class="brush: js">var btrue = new Boolean(true); +var btrueString = new Boolean('true'); +var bfalseString = new Boolean('false'); +var bSuLin = new Boolean('Su Lin'); +var bArrayProto = new Boolean([]); +var bObjProto = new Boolean({}); +</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>ECMAScript 1a Edició.</td> + <td>Standard</td> + <td>Definició inicial. Implementat a JavaScript 1.0.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.6', 'Boolean')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-boolean-objects', 'Boolean')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </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>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatIE("6.0")}}</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 for 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("Boolean.prototype")}}</li> + <li>{{Glossary("Boolean")}}</li> + <li><a href="http://en.wikipedia.org/wiki/Boolean_data_type">El tipus de dades booleà (Wikipedia)</a></li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/boolean/tosource/index.html b/files/ca/web/javascript/reference/global_objects/boolean/tosource/index.html new file mode 100644 index 0000000000..265643c1da --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/boolean/tosource/index.html @@ -0,0 +1,99 @@ +--- +title: Boolean.prototype.toSource() +slug: Web/JavaScript/Reference/Global_Objects/Boolean/toSource +translation_of: Web/JavaScript/Reference/Global_Objects/Boolean/toSource +original_slug: Web/JavaScript/Referencia/Objectes_globals/Boolean/toSource +--- +<div>{{JSRef("Objectes_standard", "Boolean")}} {{non-standard_header}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>El mètode <code><strong>toSource()</strong></code> retorna una cadena de caràcters que representa el codi font de l'objecte.</p> + +<h2 id="Syntax" name="Syntax">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>booleanObj</var>.toSource() +Boolean.toSource()</code></pre> + +<h3 id="Parameters" name="Parameters">Paràmetres</h3> + +<p>Cap.</p> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>El mètode <code>toSource</code> retorna els valors següents:</p> + +<ul> + <li>Per a objectes {{jsxref("Objectes_standard/Boolean", "Boolean")}} de la implementació de JavaScript, <code>toSource</code> retorna la següent cadena de caràcters indicant que el codi font no està disponible: + + <pre class="brush: js">function Boolean() { + [native code] +} +</pre> + </li> + <li>Per a instàncies de {{jsxref("Objectes_standard/Boolean", "Boolean")}}, <code>toSource</code> retorna una cadena de caràcters que representa el codi font.</li> +</ul> + +<p>Aquest mètode normalment és utilitzat internament per JavaScript i no explícitament al codi.</p> + +<h2 id="Especificacions">Especificacions</h2> + +<p>No forma part de cap standard. Implementat a JavaScript 1.3.</p> + +<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>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Android</th> + <th>Chrome for 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>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_Also" name="See_Also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Object.prototype.toSource()")}} {{non-standard_inline}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/boolean/tostring/index.html b/files/ca/web/javascript/reference/global_objects/boolean/tostring/index.html new file mode 100644 index 0000000000..1a7aedf3da --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/boolean/tostring/index.html @@ -0,0 +1,122 @@ +--- +title: Boolean.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Boolean/toString +translation_of: Web/JavaScript/Reference/Global_Objects/Boolean/toString +original_slug: Web/JavaScript/Referencia/Objectes_globals/Boolean/toString +--- +<div>{{JSRef("Global_Objects", "Boolean")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>El mètode <code><strong>toString()</strong></code> retorna una cadena de caràcters que representa l'objecte Boolean.</p> + +<h2 id="Syntax" name="Syntax">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>bool</var>.toString()</code></pre> + +<h3 id="Parameters" name="Parameters">Paràmetres</h3> + +<p>Cap.</p> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>L'objecte {{jsxref("Objectes_standard/Boolean", "Boolean")}} sobreescriu el mètode <code>toString</code> de l'objecte {{jsxref("Objectes_standard/Object", "Object")}}; no hereta {{jsxref("Object.prototype.toString()")}}. Per a objectes de tipus Boolean, el mètode <code>toString</code> retorna una cadena de caràcters que representa l'objecte.</p> + +<p>JavaScript crida el mètode <code>toString</code> de manera automàtica quan aquest ha de ser representat mitjançant text o bé quan un {{jsxref("Objectes_standard/Boolean", "Boolean")}} és referenciat en una concatenació de cadenes de caràcters.</p> + +<p>Per a objectes i valors de tipus {{jsxref("Objectes_standard/Boolean", "Boolean")}}, el mètode <code>toString</code> incorporat retorna la cadena de caràcters "<code>true</code>" o bé "<code>false</code>", depenent del valor de l'objecte booleà.</p> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Exemple_Utilitzar_toString">Exemple: Utilitzar <code>toString</code></h3> + +<p>Al codi següent <code>flag.toString()</code> retorna "<code>true</code>":</p> + +<pre class="brush: js">var flag = new Boolean(true); +var myVar = flag.toString(); +</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>ECMAScript 1a Edició. Implementat a JavaScript 1.1</td> + <td>Standard</td> + <td>Definició inicial.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.6.4.2', 'Boolean.prototype.toString')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-boolean.prototype.tostring', 'Boolean.prototype.toString')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </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>{{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 for 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("Object.prototype.toString()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/boolean/valueof/index.html b/files/ca/web/javascript/reference/global_objects/boolean/valueof/index.html new file mode 100644 index 0000000000..100f22e3b0 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/boolean/valueof/index.html @@ -0,0 +1,118 @@ +--- +title: Boolean.prototype.valueOf() +slug: Web/JavaScript/Reference/Global_Objects/Boolean/valueOf +translation_of: Web/JavaScript/Reference/Global_Objects/Boolean/valueOf +original_slug: Web/JavaScript/Referencia/Objectes_globals/Boolean/valueOf +--- +<div>{{JSRef("Global_Objects", "Boolean")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>El mètode <code><strong>valueOf()</strong></code> retorna el valor primitiu d'un objecte {{jsxref("Objectes_standard/Boolean", "Boolean")}}.</p> + +<h2 id="Syntax" name="Syntax">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>bool</var>.valueOf()</code></pre> + +<h3 id="Parameters" name="Parameters">Paràmetres</h3> + +<p>Cap.</p> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>El mètode <code>valueOf</code> pertanyent a {{jsxref("Objectes_standard/Boolean", "Boolean")}} retorna el valor primitiu d'un objecte o literal {{jsxref("Objectes_standard/Boolean", "Boolean")}} com a tipus de dada Boolean.</p> + +<p>Aquest mètode normalment és utilitzat internament per JavaScript i no explícitament als scripts.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Example:_Using_valueOf" name="Example:_Using_valueOf">Exemple: Utilitzar <code>valueOf</code></h3> + +<pre class="brush: js">x = new Boolean(); +myVar = x.valueOf(); // assigna false a myVar +</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>ECMAScript 1a Edició.</td> + <td>Standard</td> + <td>Definició inicial. Implementat a JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.6.4.3', 'Boolean.prototype.valueOf')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-boolean.prototype.valueof', 'Boolean.prototype.valueOf')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </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>{{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 for 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("Object.prototype.valueOf()")}}</li> +</ul> |