From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../global_objects/dataview/buffer/index.html | 101 ++++++++ .../global_objects/dataview/getfloat32/index.html | 122 +++++++++ .../reference/global_objects/dataview/index.html | 174 +++++++++++++ .../global_objects/dataview/prototype/index.html | 146 +++++++++++ .../reference/global_objects/evalerror/index.html | 161 ++++++++++++ .../global_objects/evalerror/prototype/index.html | 123 +++++++++ .../global_objects/function/arguments/index.html | 125 +++++++++ .../global_objects/function/arity/index.html | 70 ++++++ .../global_objects/function/caller/index.html | 124 +++++++++ .../reference/global_objects/function/index.html | 236 +++++++++++++++++ .../global_objects/function/length/index.html | 134 ++++++++++ .../global_objects/function/name/index.html | 153 +++++++++++ .../global_objects/function/tosource/index.html | 97 +++++++ .../global_objects/object/assign/index.html | 252 +++++++++++++++++++ .../global_objects/object/count/index.html | 82 ++++++ .../global_objects/object/eval/index.html | 85 +++++++ .../global_objects/object/freeze/index.html | 193 ++++++++++++++ .../object/getprototypeof/index.html | 124 +++++++++ .../reference/global_objects/object/index.html | 213 ++++++++++++++++ .../global_objects/object/isextensible/index.html | 138 ++++++++++ .../global_objects/object/isfrozen/index.html | 182 ++++++++++++++ .../global_objects/object/keys/index.html | 189 ++++++++++++++ .../global_objects/object/observe/index.html | 191 ++++++++++++++ .../global_objects/object/prototype/index.html | 214 ++++++++++++++++ .../global_objects/weakmap/clear/index.html | 91 +++++++ .../global_objects/weakmap/delete/index.html | 114 +++++++++ .../global_objects/weakmap/get/index.html | 115 +++++++++ .../global_objects/weakmap/has/index.html | 118 +++++++++ .../reference/global_objects/weakmap/index.html | 279 +++++++++++++++++++++ .../global_objects/weakmap/prototype/index.html | 132 ++++++++++ .../global_objects/weakmap/set/index.html | 120 +++++++++ .../global_objects/weakset/add/index.html | 103 ++++++++ .../global_objects/weakset/clear/index.html | 87 +++++++ .../global_objects/weakset/delete/index.html | 112 +++++++++ .../global_objects/weakset/has/index.html | 113 +++++++++ .../reference/global_objects/weakset/index.html | 201 +++++++++++++++ .../global_objects/weakset/prototype/index.html | 131 ++++++++++ 37 files changed, 5345 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/dataview/buffer/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/dataview/getfloat32/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/dataview/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/dataview/prototype/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/evalerror/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/evalerror/prototype/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/arguments/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/arity/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/caller/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/length/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/name/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/function/tosource/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/assign/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/count/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/eval/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/freeze/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/getprototypeof/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/isextensible/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/isfrozen/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/keys/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/observe/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/object/prototype/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/clear/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/delete/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/get/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/has/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/prototype/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakmap/set/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/add/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/clear/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/delete/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/has/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/weakset/prototype/index.html (limited to 'files/ca/web/javascript/reference/global_objects') diff --git a/files/ca/web/javascript/reference/global_objects/dataview/buffer/index.html b/files/ca/web/javascript/reference/global_objects/dataview/buffer/index.html new file mode 100644 index 0000000000..40da57fa52 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/dataview/buffer/index.html @@ -0,0 +1,101 @@ +--- +title: DataView.prototype.buffer +slug: Web/JavaScript/Reference/Global_Objects/DataView/buffer +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/buffer +--- +
{{JSRef}}
+ +

La propietat d'accés buffer representa el {{jsxref("ArrayBuffer")}} referenciat per DataView en el temps de construcció.

+ +

Sintaxi

+ +
dataview.buffer
+ +

Descripció

+ +

La propietat buffer és una propietat d'accés de la qual la seva funció d'accés és undefined, el que vol dir que només es pot llegir aquesta propietat. El valor s'estableix quan DataView és construït i no es pot canviar.

+ +

Exemples

+ +

Utilitzar la propietat buffer

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.buffer; // ArrayBuffer { byteLength: 8 }
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-get-dataview.prototype.buffer', 'DataView.prototype.buffer')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic9.0{{ CompatGeckoDesktop("15.0") }}1012.15.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic4.0{{CompatVersionUnknown}}{{ CompatGeckoMobile("15") }}{{CompatUnknown}}12.04.2
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/dataview/getfloat32/index.html b/files/ca/web/javascript/reference/global_objects/dataview/getfloat32/index.html new file mode 100644 index 0000000000..83de1562e4 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/dataview/getfloat32/index.html @@ -0,0 +1,122 @@ +--- +title: DataView.prototype.getFloat32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32 +--- +
{{JSRef}}
+ +

El mètode getFloat32() obtè un nombre decimal en coma flotant amb signe de 32 bits (float) a la posició en bytes especificada, content des del començament de {{jsxref("DataView")}}.

+ +

Sintaxi

+ +
dataview.getFloat32(byteOffset [, littleEndian])
+ +

Paràmetres

+ +
+
byteOffset
+
La posició, en bytes, des de l'inici de la vista a la que es llegiran les dades.
+
littleEndian
+
{{optional_inline}} Indica si el nombre decimal en coma flotant de 32 bits es troba emmagatzemat en format {{Glossary("Endianness", "little- o big-endian")}}. De ésser false o undefined, s'interpreta el valor com a big-endian.
+
+ +

Errors llençats

+ +
+
{{jsxref("RangeError")}}
+
Es llença si byteOffset té un valor que representa una posició més enllà del final de la vista.
+
+ +

Descripció

+ +

No hi ha cap restricció d'alineament; es poden llegir valors de múltiples bytes des de qualsevol posició.

+ +

Exemples

+ +

Utilitzar el mètode getFloat32

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getFloat32(1); // 0
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Reemplaçada per ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getfloat32', 'DataView.prototype.getFloat32')}}{{Spec2('ES6')}}Definició inicial en un estàndard ECMA.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic9.0{{CompatGeckoDesktop("15.0")}}1012.15.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic4.0{{CompatVersionUnknown}}{{ CompatGeckoMobile("15") }}{{CompatUnknown}}12.04.2
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/dataview/index.html b/files/ca/web/javascript/reference/global_objects/dataview/index.html new file mode 100644 index 0000000000..90c9d640ee --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/dataview/index.html @@ -0,0 +1,174 @@ +--- +title: DataView +slug: Web/JavaScript/Reference/Global_Objects/DataView +tags: + - Constructor + - DataView + - JavaScript + - NeedsTranslation + - TopicStub + - TypedArrays +translation_of: Web/JavaScript/Reference/Global_Objects/DataView +--- +
{{JSRef}}
+ +

The DataView view provides a low-level interface for reading data from and writing it to an {{jsxref("ArrayBuffer")}}.

+ +

Syntax

+ +
new DataView(buffer [, byteOffset [, byteLength]])
+ +

Parameters

+ +
+
buffer
+
An existing {{jsxref("ArrayBuffer")}} to use as the storage for the new DataView object.
+
byteOffset {{optional_inline}}
+
The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the view of the buffer will start with the first byte.
+
byteLength {{optional_inline}}
+
The number of elements in the byte array. If unspecified, length of the view will match the buffer's length.
+
+ +

Return value

+ +

A new DataView object representing the specified data buffer.

+ +

Errors thrown

+ +
+
{{jsxref("RangeError")}}
+
Thrown if the byteOffset and byteLength result in the specified view extending past the end of the buffer.
+
+ +

Description

+ +

Detect endianness

+ +

You'll probably need to detect the type of architecture your script is running, here is a little trick to check it. See {{Glossary("Endianness")}} for more information.

+ +
var littleEndian = (function() {
+  var buffer = new ArrayBuffer(2);
+  new DataView(buffer).setInt16(0, 256, true);
+  return new Int16Array(buffer)[0] === 256;
+})();
+console.log(littleEndian); // true or false
+
+ +

Properties

+ +
+
DataView.length
+
The DataView constructor's length property whose value is 3.
+
{{jsxref("DataView.prototype")}}
+
Allows the addition of properties to all DataView objects.
+
+ +

DataView instances

+ +

All DataView instances inherit from {{jsxref("DataView.prototype")}}.

+ +

Properties

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Properties')}}

+ +

Methods

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Methods')}}

+ +

Example

+ +
var buffer = new ArrayBuffer(16);
+var dv = new DataView(buffer, 0);
+
+dv.setInt16(1, 42);
+dv.getInt16(1); //42
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-dataview-constructor', 'DataView')}}{{Spec2('ES6')}}Initial definition in an ECMA standard
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support9.0{{CompatGeckoDesktop("15.0")}}1012.15.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support4.0{{CompatVersionUnknown}}{{CompatGeckoMobile("15")}}{{CompatUnknown}}12.04.2
+
+ +

Firefox-specific notes

+ +

Starting with Gecko / SpiderMonkey 40 {{geckoRelease(40)}}, DataView requires to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling DataView() as a function without new, will throw a {{jsxref("TypeError")}} from now on.

+ +
var dv = DataView(buffer, 0);
+// TypeError: calling a builtin DataView constructor without new is forbidden
+ +
var dv = new DataView(buffer, 0);
+ +

See also

+ + diff --git a/files/ca/web/javascript/reference/global_objects/dataview/prototype/index.html b/files/ca/web/javascript/reference/global_objects/dataview/prototype/index.html new file mode 100644 index 0000000000..203e5076e4 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/dataview/prototype/index.html @@ -0,0 +1,146 @@ +--- +title: DataView.prototype +slug: Web/JavaScript/Reference/Global_Objects/DataView/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/DataView +--- +
{{JSRef}}
+ +

La propietat DataView.prototype representa el prototip de l'objecte {{jsxref("DataView")}}.

+ +
{{js_property_attributes(0,0,0)}}
+ +

Descripció

+ +

Les instàncies DataView hereten de DataView.prototype. Com passa amb tots els constructors, podeu canviar l'objecte prototip del constructor per produir canvis a totes les instàncies DataView.

+ +

Propietats

+ +
+
DataView.prototype.constructor
+
Especifica la funció que crea un prototip de l'objecte. El valor inicial és el constructor integrat estàndard DataView.
+
{{jsxref("DataView.prototype.buffer")}} {{readonlyInline}}
+
L'{{jsxref("ArrayBuffer")}} referenciat per aquesta vista. Fixat en el temps de construcció i per tant és només de lectura.
+
{{jsxref("DataView.prototype.byteLength")}} {{readonlyInline}}
+
La llargària (en bytes) d'aquesta vista des del començament del seu {{jsxref("ArrayBuffer")}}. Fixat en el temps de construcció i per tant és només de lectura.
+
{{jsxref("DataView.prototype.byteOffset")}} {{readonlyInline}}
+
La posició (en bytes) d'aquesta vista des de l'inici del seu {{jsxref("ArrayBuffer")}}. Fixat en el temps de construcció i per tant és només de lectura.
+
+ +

Mètodes

+ +

Lectura

+ +
+
{{jsxref("DataView.prototype.getInt8()")}}
+
Obté un nombre sencer (byte) de 8 bits amb signe al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getUint8()")}}
+
Obté un nombre sencer sense signe de 8 bits (unsigned byte) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getInt16()")}}
+
Obté un nombre sencer de 16 bits (short) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getUint16()")}}
+
Obté un nombre sencer sense signe de 16 bits (unsigned short) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getInt32()")}}
+
Obté un nombre sencer de 32 bits (long) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getUint32()")}}
+
Obté un nombre sencer sense signe de 31 bits (unsigned long) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getFloat32()")}}
+
Obté un nombre en coma flotant amb signe de 32 bits (float) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.getFloat64()")}}
+
Obté un nombre en coma flotant amb signe de 64 bits (double) al byte de posició especificat des de l'inici de la vista.
+
+ +

Escritura

+ +
+
{{jsxref("DataView.prototype.setInt8()")}}
+
Emmagatzema el valor d'un nombre sencer de 8 bits (byte) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setUint8()")}}
+
Emmagatzema el valor d'un nombre sencer sense signe de 8 bits (unsigned byte) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setInt16()")}}
+
Emmagatzema el valor d'un nombre sencer amb signe de 16 bits (short) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setUint16()")}}
+
Emmagatzema el valor d'un nombre sencer sense signe de 16 bits (unsigned short) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setInt32()")}}
+
Emmagatzema el valor d'un nombre sencer amb signe de 32 bits (long) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setUint32()")}}
+
Emmagatzema el valor d'un nombre sencer sense signe de 32 bits  (unsigned long) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setFloat32()")}}
+
Emmagatzema el valor d'un nombre en coma flotant amb signe de 32 bits (float) al byte de posició especificat des de l'inici de la vista.
+
{{jsxref("DataView.prototype.setFloat64()")}}
+
Emmagatzema el valor d'un nombre en coma flotant amb signe de 64 bits (double) al byte de posició especificat des de l'inici de la vista.
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-dataview.prototype', 'DataView.prototype')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegador

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic9.0{{ CompatGeckoDesktop("15.0") }}1012.15.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic4.0{{CompatVersionUnknown}}{{CompatGeckoMobile("15")}}{{CompatUnknown}}12.04.2
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/evalerror/index.html b/files/ca/web/javascript/reference/global_objects/evalerror/index.html new file mode 100644 index 0000000000..65a4df349e --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/evalerror/index.html @@ -0,0 +1,161 @@ +--- +title: EvalError +slug: Web/JavaScript/Reference/Global_Objects/EvalError +tags: + - Error + - EvalError + - JavaScript + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/EvalError +--- +
{{JSRef}}
+ +

The EvalError object indicates an error regarding the global {{jsxref("Global_Objects/eval", "eval()")}} function.

+ +

Syntax

+ +
new EvalError([message[, fileName[, lineNumber]]])
+ +

Parameters

+ +
+
message
+
Optional. Human-readable description of the error
+
fileName {{non-standard_inline}}
+
Optional. The name of the file containing the code that caused the exception
+
lineNumber {{non-standard_inline}}
+
Optional. The line number of the code that caused the exception
+
+ +

Description

+ +

An EvalError is thrown when the global {{jsxref("Global_Objects/eval", "eval()")}} function is used improperly.

+ +

Properties

+ +
+
{{jsxref("EvalError.prototype")}}
+
Allows the addition of properties to an EvalError object.
+
+ +

Methods

+ +

The global EvalError contains no methods of its own, however, it does inherit some methods through the prototype chain.

+ +

EvalError instances

+ +

Properties

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/prototype', 'Properties')}}
+ +

Methods

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/prototype', 'Methods')}}
+ +

Examples

+ +

EvalError is not used now, and never be thrown by the runtime.

+ +

Creating an EvalError

+ +
try {
+  throw new EvalError('Hello', 'someFile.js', 10);
+} catch (e) {
+  console.log(e instanceof EvalError); // true
+  console.log(e.message);              // "Hello"
+  console.log(e.name);                 // "EvalError"
+  console.log(e.fileName);             // "someFile.js"
+  console.log(e.lineNumber);           // 10
+  console.log(e.columnNumber);         // 0
+  console.log(e.stack);                // "@Scratchpad/2:2:9\n"
+}
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES3')}}{{Spec2('ES3')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.11.6.1', 'EvalError')}}{{Spec2('ES5.1')}}Not used in this specification. Present for backward compatibility.
{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-evalerror', 'EvalError')}}{{Spec2('ES6')}}Not used in this specification. Present for backward compatibility.
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

See also

+ + diff --git a/files/ca/web/javascript/reference/global_objects/evalerror/prototype/index.html b/files/ca/web/javascript/reference/global_objects/evalerror/prototype/index.html new file mode 100644 index 0000000000..8aecc42c15 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/evalerror/prototype/index.html @@ -0,0 +1,123 @@ +--- +title: EvalError.prototype +slug: Web/JavaScript/Reference/Global_Objects/EvalError/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/EvalError +--- +
{{JSRef}}
+ +

La propietat EvalError.prototype representa el prototip del constructor {{jsxref("EvalError")}}.

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

Totes les instàncies {{jsxref("EvalError")}} hereten de EvalError.prototype. Es pot utilitzar el prototip per afegir propietats o mètodes a totes les instàncies.

+ +

Propietats

+ +
+
EvalError.prototype.constructor
+
Especifica la funció que ha creat el prototip d'una instància.
+
{{jsxref("Error.prototype.message", "EvalError.prototype.message")}}
+
Missatge d'error. Tot i que l'ECMA-262 especifica que {{jsxref("EvalError")}} hauria de proveir la seva pròpia propietat message, en SpiderMonkey, hereta {{jsxref("Error.prototype.message")}}.
+
{{jsxref("Error.prototype.name", "EvalError.prototype.name")}}
+
Nom de l'error. Heretat de {{jsxref("Error")}}.
+
{{jsxref("Error.prototype.fileName", "EvalError.prototype.fileName")}}
+
Camí cap al fitxer que ha llançat aquest error. Heretat de {{jsxref("Error")}}.
+
{{jsxref("Error.prototype.lineNumber", "EvalError.prototype.lineNumber")}}
+
Número de línia en el fitxer que ha llançat aquest error. Heretat de {{jsxref("Error")}}.
+
{{jsxref("Error.prototype.columnNumber", "EvalError.prototype.columnNumber")}}
+
Número de columna en la línia que ha llançat aquest error. Heretat de {{jsxref("Error")}}.
+
{{jsxref("Error.prototype.stack", "EvalError.prototype.stack")}}
+
Traça de l'error. Heretat de {{jsxref("Error")}}.
+
+ +

Mètodes

+ +

Tot i que l'objecte prototip {{jsxref("EvalError")}} no contè cap mètode en si mateix, les instàncies  {{jsxref("EvalError")}} hereten alguns mètodes a través de la cadena prototip.

+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial
{{SpecName('ES5.1', '#sec-15.11.7.6', 'NativeError.prototype')}}{{Spec2('ES5.1')}}Definit com a NativeError.prototype.
{{SpecName('ES6', '#sec-nativeerror.prototype', 'NativeError.prototype')}}{{Spec2('ES6')}}Definit com a NativeError.prototype.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/arguments/index.html b/files/ca/web/javascript/reference/global_objects/function/arguments/index.html new file mode 100644 index 0000000000..6371caeb23 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/arguments/index.html @@ -0,0 +1,125 @@ +--- +title: Function.arguments +slug: Web/JavaScript/Reference/Global_Objects/Function/arguments +translation_of: Web/JavaScript/Reference/Global_Objects/Function/arguments +--- +
{{JSRef}} {{deprecated_header}}
+ +

La propietat function.arguments es refereix a un objecte que s'assembla a una array corresponent als arguments passats a una funció. Utilitzeu la variable simple {{jsxref("Functions/arguments", "arguments")}}.

+ +

Descripció

+ +

La sintaxis function.arguments és obsoleta. El camí recomanat per accedir a l'objecte {{jsxref("Functions/arguments", "arguments")}} disponible en les funcions requereix simplement referir-se a la variable{{jsxref("Functions/arguments", "arguments")}}.

+ +

En cas de recursivitat, és a dir, si la funció f apareix vàries vegades en la pila de crides, el valor det f.arguments representa els arguments corresponents a la invocació més recent de la funció.

+ +

El valor del la propietat arguments normalment és null si no hi ha una invocació excel·lent de la funció (això vol dir, que s'ha cridat la funció però la seva execució encara no s'ha acabat).

+ +

Exemples

+ +
function f(n) { g(n - 1); }
+
+function g(n) {
+  console.log('before: ' + g.arguments[0]);
+  if (n > 0) { f(n); }
+  console.log('after: ' + g.arguments[0]);
+}
+
+f(2);
+
+console.log('returned: ' + g.arguments);
+
+// Resultat
+
+// abans: 1
+// abans: 0
+// després: 0
+// després: 1
+// retorn: null
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat en JavaScript 1.0. Obsolet a favor de {{jsxref("Functions/arguments", "arguments")}} en ES3.
{{SpecName('ES5.1', '#sec-10.6', 'arguments object')}}{{Spec2('ES5.1')}}{{jsxref("Functions/arguments", "arguments")}} object
{{SpecName('ES6', '#sec-arguments-object', 'arguments object')}}{{Spec2('ES6')}}{{jsxref("Functions/arguments", "arguments")}} object
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterístcaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/arity/index.html b/files/ca/web/javascript/reference/global_objects/function/arity/index.html new file mode 100644 index 0000000000..d330307535 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/arity/index.html @@ -0,0 +1,70 @@ +--- +title: Function.arity +slug: Web/JavaScript/Reference/Global_Objects/Function/arity +translation_of: Archive/Web/JavaScript/Function.arity +--- +
{{JSRef}} {{obsolete_header}}
+ +

La propietat arity solia retornar el número d'arguments esperats per la funció, tanmateix, ja no existeix i s'ha reemplaçat per la propietat {{jsxref("Function.prototype.length")}}.

+ +

Especificacions

+ +

Implementat en JavaScript 1.2. Obsolet en JavaScript 1.4.}

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/caller/index.html b/files/ca/web/javascript/reference/global_objects/function/caller/index.html new file mode 100644 index 0000000000..613e163d6a --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/caller/index.html @@ -0,0 +1,124 @@ +--- +title: Function.caller +slug: Web/JavaScript/Reference/Global_Objects/Function/caller +translation_of: Web/JavaScript/Reference/Global_Objects/Function/caller +--- +
{{JSRef}} {{non-standard_header}}
+ +

La propietat function.caller retorna la funció que ha invocat la funció especificada.

+ +

Descripció

+ +

SI la funció f ha estat invocada pel codi de nivell superior, el valor de f.caller és {{jsxref("null")}}, sinó és la funció que ha cridat f.

+ +

Aquesta propietat reemplaça la propietat obsoleta {{jsxref("Functions/arguments/caller", "arguments.caller")}} de l'objecte {{jsxref("Functions/arguments", "arguments")}}.

+ +

La propietat especial __caller__, la qual retorna l'objecte activatwhich returned the activation object of the caller thus allowing to reconstruct the stack, was removed for security reasons.

+ +

Notes

+ +

Vegeu que en cas de recursió, no podeu reconstruir la pila de crida fent servir aquesta propietat. C that in case of recursion, you can't reconstruct the call stack using this property. Tingueu en compte:

+ +
function f(n) { g(n - 1); }
+function g(n) { if (n > 0) { f(n); } else { stop(); } }
+f(2);
+
+ +

At the moment stop() is called the call stack will be:

+ +
f(2) -> g(1) -> f(1) -> g(0) -> stop()
+
+ +

El següent és cert:

+ +
stop.caller === g && f.caller === g && g.caller === f
+
+ +

so if you tried to get the stack trace in the stop() function like this:

+ +
var f = stop;
+var stack = 'Stack trace:';
+while (f) {
+  stack += '\n' + f.name;
+  f = f.caller;
+}
+
+ +

El bucle mai s'aturaria.

+ +

Exemples

+ +

Checking the value of a function's caller property

+ +

El codi següent comprova que el valor following code checks the value a function's caller property.

+ +
function myFunc() {
+  if (myFunc.caller == null) {
+    return 'The function was called from the top!';
+  } else {
+    return 'This function\'s caller was ' + myFunc.caller;
+  }
+}
+
+ +

Especificacions

+ +

No forma part de cap especificació. Implementat en JavaScript 1.5.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}8.0{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/index.html b/files/ca/web/javascript/reference/global_objects/function/index.html new file mode 100644 index 0000000000..9cb0571d13 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/index.html @@ -0,0 +1,236 @@ +--- +title: Function +slug: Web/JavaScript/Reference/Global_Objects/Function +tags: + - Constructor + - Function + - JavaScript + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/Function +--- +
{{JSRef}}
+ +

The Function constructor creates a new Function object. In JavaScript every function is actually a Function object.

+ +

Syntax

+ +
new Function ([arg1[, arg2[, ...argN]],] functionBody)
+ +

Parameters

+ +
+
arg1, arg2, ... argN
+
Names to be used by the function as formal argument names. Each must be a string that corresponds to a valid JavaScript identifier or a list of such strings separated with a comma; for example "x", "theValue", or "a,b".
+
functionBody
+
A string containing the JavaScript statements comprising the function definition.
+
+ +

Description

+ +

Function objects created with the Function constructor are parsed when the function is created. This is less efficient than declaring a function with a function expression or function statement and calling it within your code, because such functions are parsed with the rest of the code.

+ +

All arguments passed to the function are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed.

+ +
+

Note: Functions created with the Function constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the Function constructor was called. This is different from using {{jsxref("eval")}} with code for a function expression.

+
+ +

Invoking the Function constructor as a function (without using the new operator) has the same effect as invoking it as a constructor.

+ +

Properties and Methods of Function

+ +

The global Function object has no methods or properties of its own, however, since it is a function itself it does inherit some methods and properties through the prototype chain from {{jsxref("Function.prototype")}}.

+ +

Function prototype object

+ +

Properties

+ +
{{page('/en-US/docs/JavaScript/Reference/Global_Objects/Function/prototype', 'Properties')}}
+ +

Methods

+ +
{{page('/en-US/docs/JavaScript/Reference/Global_Objects/Function/prototype', 'Methods')}}
+ +

Function instances

+ +

Function instances inherit methods and properties from {{jsxref("Function.prototype")}}. As with all constructors, you can change the constructor's prototype object to make changes to all Function instances.

+ +

Examples

+ +

Specifying arguments with the Function constructor

+ +

The following code creates a Function object that takes two arguments.

+ +
// Example can be run directly in your JavaScript console
+
+// Create a function that takes two arguments and returns the sum of those arguments
+var adder = new Function('a', 'b', 'return a + b');
+
+// Call the function
+adder(2, 6);
+// > 8
+
+ +

The arguments "a" and "b" are formal argument names that are used in the function body, "return a + b".

+ +

A recursive shortcut to massively modify the DOM

+ +

Creating functions with the Function constructor is one of the ways to dynamically create an indeterminate number of new objects with some executable code into the global scope from a function. The following example (a recursive shortcut to massively modify the DOM) is impossible without the invocation of the Function constructor for each new query if you want to avoid closures.

+ +
<!doctype html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>MDN Example - a recursive shortcut to massively modify the DOM</title>
+<script type="text/javascript">
+var domQuery = (function() {
+  var aDOMFunc = [
+    Element.prototype.removeAttribute,
+    Element.prototype.setAttribute,
+    CSSStyleDeclaration.prototype.removeProperty,
+    CSSStyleDeclaration.prototype.setProperty
+  ];
+
+  function setSomething(bStyle, sProp, sVal) {
+    var bSet = Boolean(sVal), fAction = aDOMFunc[bSet | bStyle << 1],
+        aArgs = Array.prototype.slice.call(arguments, 1, bSet ? 3 : 2),
+        aNodeList = bStyle ? this.cssNodes : this.nodes;
+
+    if (bSet && bStyle) { aArgs.push(''); }
+    for (
+      var nItem = 0, nLen = this.nodes.length;
+      nItem < nLen;
+      fAction.apply(aNodeList[nItem++], aArgs)
+    );
+    this.follow = setSomething.caller;
+    return this;
+  }
+
+  function setStyles(sProp, sVal) { return setSomething.call(this, true, sProp, sVal); }
+  function setAttribs(sProp, sVal) { return setSomething.call(this, false, sProp, sVal); }
+  function getSelectors() { return this.selectors; };
+  function getNodes() { return this.nodes; };
+
+  return (function(sSelectors) {
+    var oQuery = new Function('return arguments.callee.follow.apply(arguments.callee, arguments);');
+    oQuery.selectors = sSelectors;
+    oQuery.nodes = document.querySelectorAll(sSelectors);
+    oQuery.cssNodes = Array.prototype.map.call(oQuery.nodes, function(oInlineCSS) { return oInlineCSS.style; });
+    oQuery.attributes = setAttribs;
+    oQuery.inlineStyle = setStyles;
+    oQuery.follow = getNodes;
+    oQuery.toString = getSelectors;
+    oQuery.valueOf = getNodes;
+    return oQuery;
+  });
+})();
+</script>
+</head>
+
+<body>
+
+<div class="testClass">Lorem ipsum</div>
+<p>Some text</p>
+<div class="testClass">dolor sit amet</div>
+
+<script type="text/javascript">
+domQuery('.testClass')
+  .attributes('lang', 'en')('title', 'Risus abundat in ore stultorum')
+  .inlineStyle('background-color', 'black')('color', 'white')('width', '100px')('height', '50px');
+</script>
+</body>
+
+</html>
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.3', 'Function')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-function-objects', 'Function')}}{{Spec2('ES6')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

See also

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/length/index.html b/files/ca/web/javascript/reference/global_objects/function/length/index.html new file mode 100644 index 0000000000..2af00ebf41 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/length/index.html @@ -0,0 +1,134 @@ +--- +title: Function.length +slug: Web/JavaScript/Reference/Global_Objects/Function/length +translation_of: Web/JavaScript/Reference/Global_Objects/Function/length +--- +
{{JSRef}}
+ +

La propietat length especifica el nombre d'arguments que la funció espera.

+ +
{{js_property_attributes(0,0,1)}}
+ +

Descripció

+ +

length és una propietat d'un objecte funció, i indica quants arguments la funció espera,  és a dir, el nombre de paràmetres formals. Aquest nombre no inclou el  {{jsxref("rest_parameters", "rest parameter", "", 1)}}. Per contra, {{jsxref("Functions_and_function_scope/arguments/length", "arguments.length")}} és local a la funció i retorna el nombre d'arguments que s'han passat a la funció.

+ +

Propietat Data del constructor Function

+ +

El constructor {{jsxref("Function")}} és per ell mateix un objecte {{jsxref("Function")}}. La seva propietat data length pren un valor d'1. Els atributs de la propietat són: Writable: false, Enumerable: false, Configurable: true.

+ +

Propietat de l'objecte prototipus Function

+ +

La propietat length de l'objecte prototipus {{jsxref("Function")}} pren un valor de 0.

+ +

Exemples

+ +
console.log(Function.length); /* 1 */
+
+console.log((function()        {}).length); /* 0 */
+console.log((function(a)       {}).length); /* 1 */
+console.log((function(a, b)    {}).length); /* 2 etc. */
+console.log((function(...args) {}).length); /* 0, la resta de paràmetres no es conta */
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definció inicial. Implementat en JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.3.5.1', 'Function.length')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-function-instances-length', 'Function.length')}}{{Spec2('ES6')}}L'atribut configurable d'aquesta propietat és ara  true.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Configurable: true{{CompatUnknown}}{{CompatGeckoDesktop(37)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Configurable: true{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile(37)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/function/name/index.html b/files/ca/web/javascript/reference/global_objects/function/name/index.html new file mode 100644 index 0000000000..6f88ba9be2 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/name/index.html @@ -0,0 +1,153 @@ +--- +title: Function.name +slug: Web/JavaScript/Reference/Global_Objects/Function/name +translation_of: Web/JavaScript/Reference/Global_Objects/Function/name +--- +
{{JSRef}}
+ +

La propietat function.name retorna el nom de la funció.

+ +
{{js_property_attributes(0,0,1)}}
+ +
Vegeu que en les implementacions no estàndards anteriors a ES2015 l'atribut configurable també era false.
+ +

Descripció

+ +

La propietat name retorna el nom de la funció, o una cadena buida per les funcions anònimes.

+ +
function fesAlgo() {}
+
+console.log(desAlgo.name); // escriu "fesAlgo"
+
+ +

Les funcions creades amb la sintaxis new Function(...) o sols Function(...)tenen la seva propietat name en una cadena buida. En els exemples següents es creen funcions anònimes , de forma que name retorna una cadena buida:

+ +
var f = function() {};
+var object = {
+  someMethod: function() {}
+};
+
+console.log(f.name == ''); // true
+console.log(object.someMethod.name == ''); // també true
+
+ +

Es pot definir una funció amb un nom en un {{jsxref("Operators/Function", "function expression", "", 1)}}:

+ +
var object = {
+  someMethod: function object_someMethod() {}
+};
+console.log(object.someMethod.name); // logs "object_someMethod"
+
+try { object_someMethod } catch(e) { console.log(e); }
+// ReferenceError: object_someMethod no està definit
+
+ +

No es pot canviar el nom de la funció, aquesta propietat és només llegible:

+ +
var object = {
+  // anònima
+  someMethod: function() {}
+};
+
+object.someMethod.name = 'someMethod';
+console.log(object.someMethod.name); // cadena buida, someMethod és anònima.
+
+ +

Per canviar-ho, es pot utilitzar {{jsxref("Object.defineProperty()")}}.

+ +

Exemples

+ +

Es pot utilitzar obj.constructor.name per comprovar la "classe" d'un objecte:

+ +
function a() {}
+
+var b = new a();
+
+console.log(b.constructor.name); // escriu "a"
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES2015', '#sec-name', 'name')}}{{Spec2('ES2015')}}Definició inicial.
+ +

Comptabilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic33{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Configurable: true43{{CompatGeckoDesktop(38)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
Configurable: true{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile(38)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
diff --git a/files/ca/web/javascript/reference/global_objects/function/tosource/index.html b/files/ca/web/javascript/reference/global_objects/function/tosource/index.html new file mode 100644 index 0000000000..27f135ce13 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/tosource/index.html @@ -0,0 +1,97 @@ +--- +title: Function.prototype.toSource() +slug: Web/JavaScript/Reference/Global_Objects/Function/toSource +translation_of: Web/JavaScript/Reference/Global_Objects/Function/toSource +--- +
{{JSRef}} {{non-standard_header}}
+ +

El mètode toSource()retorna una cadena que representa el codi font de l'objecte.

+ +

Sintaxi

+ +
function.toSource();
+Function.toSource();
+
+ +

Paràmetres

+ +

Cap.

+ +

Descripció

+ +

El mètode toSource retorna els valors següents:

+ + + +

Aquest mètode se sol cridar internament per JavaScript i no explícitament en el codi. Podeu cridar toSource durant la depuració per examinar el contingut d'un objecte.

+ +

Especificacions

+ +

No forma part de cap estàndard. Implementat en JavaScript 1.3.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/assign/index.html b/files/ca/web/javascript/reference/global_objects/object/assign/index.html new file mode 100644 index 0000000000..855b5654a6 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/assign/index.html @@ -0,0 +1,252 @@ +--- +title: Object.assign() +slug: Web/JavaScript/Reference/Global_Objects/Object/assign +translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign +--- +
{{JSRef}}
+ +

El mètode Object.assign() s'utilitza per copiar els valors de totes les propietats enumerables pròpies d'un o més objectes d'orígens a un objecte objectiu o destí. Retornarà l'objecte destí.

+ +

Sintaxi

+ +
Object.assign(target, ...orígens)
+ +

Paràmetres

+ +
+
target
+
L'objecte destí.
+
sources
+
El(s) objecte(s) d'orígen.
+
+ +

Valor retornat

+ +

L'objecte destí (o objectiu) es retornat.

+ +

Descripció

+ +

El mètode Object.assign() només copia propietats enumerables i pròpies d'un objecte orígen a un objecte destí. S'utilitza [[Get]] a l'orígen i [[Put]] al destí, de forma que invocarà getters i setters. Per tant, assigna propietats en comptes de només copiar o definir noves propietats. Axò pot fer que sigui inadequat per juntar noves propietats en un prototipus si les fonts de la unió contenen getters. Per copiar definicions de la propietat, incloent la seva enumerabilitat, en prototipus s'ha de fer servir {{jsxref("Object.getOwnPropertyDescriptor()")}} i {{jsxref("Object.defineProperty()")}}.

+ +

Tant la propietat {{jsxref("String")}} com la propietat {{jsxref("Symbol")}} són copiades.

+ +

En cas d'error, per exemple si una propietat no és modificable, un {{jsxref("TypeError")}} s'incrementarà i l'objecte target object es mantindrà sense canvis.

+ +

Vegeu que Object.assign() does not throw on {{jsxref("null")}} or {{jsxref("undefined")}} source values.

+ +

Exemples

+ +

Clonar un objecte

+ +
var obj = { a: 1 };
+var copy = Object.assign({}, obj);
+console.log(copy); // { a: 1 }
+
+ +

Unir objectes

+ +
var o1 = { a: 1 };
+var o2 = { b: 2 };
+var o3 = { c: 3 };
+
+var obj = Object.assign(o1, o2, o3);
+console.log(obj); // { a: 1, b: 2, c: 3 }
+console.log(o1);  // { a: 1, b: 2, c: 3 }, L'objecte de destinació es canvia
+ +

Copiar propietats  symbol-typed

+ +
var o1 = { a: 1 };
+var o2 = { [Symbol('foo')]: 2 };
+
+var obj = Object.assign({}, o1, o2);
+console.log(obj); // { a: 1, [Symbol("foo")]: 2 }
+
+ +

Les propietats heretades i les propietats no enumerables no es poden copiar

+ +
var obj = Object.create({ foo: 1 }, { // foo és una propietat heretada.
+  bar: {
+    value: 2  // bar és una propietat no enumerable.
+  },
+  baz: {
+    value: 3,
+    enumerable: true  // baz is an own enumerable property.
+  }
+});
+
+var copy = Object.assign({}, obj);
+console.log(copy); // { baz: 3 }
+
+ +

Primitives will be wrapped to objects

+ +
var v1 = '123';
+var v2 = true;
+var v3 = 10;
+var v4 = Symbol('foo')
+
+var obj = Object.assign({}, v1, null, v2, undefined, v3, v4);
+// Primitives will be wrapped, null and undefined will be ignored.
+// Note, only string wrappers can have own enumerable properties.
+console.log(obj); // { "0": "1", "1": "2", "2": "3" }
+
+ +

Exceptions will interrupt the ongoing copying task

+ +
var target = Object.defineProperty({}, 'foo', {
+  value: 1,
+  writeable: false
+}); // target.foo is a read-only property
+
+Object.assign(target, { bar: 2 }, { foo2: 3, foo: 3, foo3: 3 }, { baz: 4 });
+// TypeError: "foo" is read-only
+// The Exception is thrown when assigning target.foo
+
+console.log(target.bar);  // 2, the first source was copied successfully.
+console.log(target.foo2); // 3, the first property of the second source was copied successfully.
+console.log(target.foo);  // 1, exception is thrown here.
+console.log(target.foo3); // undefined, assign method has finished, foo3 will not be copied.
+console.log(target.baz);  // undefined, the third source will not be copied either.
+
+ +

Copying accessors

+ +
var obj = {
+  foo: 1,
+  get bar() {
+    return 2;
+  }
+};
+
+var copy = Object.assign({}, obj);
+console.log(copy);
+// { foo: 1, bar: 2 }, the value of copy.bar is obj.bar's getter's return value.
+
+// This is an assign function which can copy accessors.
+function myAssign(target, ...sources) {
+  sources.forEach(source => {
+    Object.defineProperties(target, Object.keys(source).reduce((descriptors, key) => {
+      descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
+      return descriptors;
+    }, {}));
+  });
+  return target;
+}
+
+var copy = myAssign({}, obj);
+console.log(copy);
+// { foo:1, get bar() { return 2 } }
+
+ +

Polyfill

+ +

This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway:

+ +
if (!Object.assign) {
+  Object.defineProperty(Object, 'assign', {
+    enumerable: false,
+    configurable: true,
+    writable: true,
+    value: function(target) {
+      'use strict';
+      if (target === undefined || target === null) {
+        throw new TypeError('Cannot convert first argument to object');
+      }
+
+      var to = Object(target);
+      for (var i = 1; i < arguments.length; i++) {
+        var nextSource = arguments[i];
+        if (nextSource === undefined || nextSource === null) {
+          continue;
+        }
+        nextSource = Object(nextSource);
+
+        var keysArray = Object.keys(Object(nextSource));
+        for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
+          var nextKey = keysArray[nextIndex];
+          var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
+          if (desc !== undefined && desc.enumerable) {
+            to[nextKey] = nextSource[nextKey];
+          }
+        }
+      }
+      return to;
+    }
+  });
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES2015', '#sec-object.assign', 'Object.assign')}}{{Spec2('ES2015')}}Definició inicial
+ +

Compatibilitat de navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracteristicaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("45")}}{{CompatGeckoDesktop("34")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("34")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/count/index.html b/files/ca/web/javascript/reference/global_objects/object/count/index.html new file mode 100644 index 0000000000..ed84c7006c --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/count/index.html @@ -0,0 +1,82 @@ +--- +title: Object.prototype.__count__ +slug: Web/JavaScript/Reference/Global_Objects/Object/count +translation_of: Archive/Web/JavaScript/Object.count +--- +
{{JSRef}} {{obsolete_header("2")}}
+ +

La propietat __count__ s'utilitzava per emmagatzemar el recompte de les propietats enumerables d'un objecte, però s'ha eliminat.

+ +

Sintaxi

+ +
obj.__count__
+ +

Exemples

+ +
{ 1: 1 }.__count__              // 1
+[].__count__                    // 0
+[1].__count__                   // 1
+[1, /* hole */, 2, 3].__count__ // 3
+
+ +

Especificacions

+ +

No forma part de cap especificació.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/eval/index.html b/files/ca/web/javascript/reference/global_objects/object/eval/index.html new file mode 100644 index 0000000000..8c43cf423a --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/eval/index.html @@ -0,0 +1,85 @@ +--- +title: Object.prototype.eval() +slug: Web/JavaScript/Reference/Global_Objects/Object/eval +translation_of: Archive/Web/JavaScript/Object.eval +--- +
{{JSRef}} {{obsolete_header}}
+ +

El mètode Object.eval() solia avaluar una cadena del codi JavaScript en el context d'un objecte, tanmateix, aquest mètode s'ha eliminat.

+ +

Sintaxi

+ +
obj.eval(cadena)
+ +

Paràmetres

+ +
+
cadena
+
Qualsevol cadena que representi una expressió JavaScript, sentència, o una seqüència de sentències. L'expressió pot incloure variables i propietats d'objectes ja existents.
+
+ +

Descripció

+ +

El mètode eval ja no es pot utilitzar com a mètode d'un objecte. Utilitzeu la funció de més alt nivell {{jsxref("Global_Objects/eval", "eval()")}} per aquesta finalitat.

+ +

Especificacions

+ +

No forma part de cap especificació.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/freeze/index.html b/files/ca/web/javascript/reference/global_objects/object/freeze/index.html new file mode 100644 index 0000000000..1231afe27f --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/freeze/index.html @@ -0,0 +1,193 @@ +--- +title: Object.freeze() +slug: Web/JavaScript/Reference/Global_Objects/Object/freeze +translation_of: Web/JavaScript/Reference/Global_Objects/Object/freeze +--- +
{{JSRef}}
+ +

El mètode Object.freeze() congela un objecte: és a dir, evita que se li puguin afegir noves propietats, eliminar propietats ja existents així com modificar els paràmetres d'enumerabilitat, configurabilitat i possibilitat d'escriptura de les propietats existents. Això, en essència fa que l'objecte esdevingui immutable a efectes pràctics. El mètode retorna l'objecte que s'ha congelat.

+ +

Sintaxi

+ +
Object.freeze(obj)
+ +

Paràmetres

+ +
+
obj
+
L'objecte a congelar.
+
+ +

Descripció

+ +

Res pot ser afegit o eliminat del conjunt de propietats d'un objecte congelat. Qualsevol intent fallarà o bé sense reportar cap error o bé llençant una excepció {{jsxref("TypeError")}} (és l'excepció més freqüent que serà llençada però en pot llençat altres tipus; a l'utilitzar el {{jsxref("Strict_mode", "mode estricte", "", 1)}}).

+ +

Congelar un objecte també evita que es puguin modificar els valors de les seves propietats. Les propietats d'accés (getters i setters) segueixen funcionan (donant la il·lusió que s'ha canviat el valor). Cal advertir, però, que els valors que siguin objectes sí que es poden modificar, a no ser que aquests objectes també estiguin congelats.

+ +

Exemples

+ +
var obj = {
+  prop: function() {},
+  foo: 'bar'
+};
+
+// Es poden afegir noves propietats, així com canviar o eliminar les propietats ja existents
+obj.foo = 'baz';
+obj.lumpy = 'woof';
+delete obj.prop;
+
+var o = Object.freeze(obj);
+
+assert(Object.isFrozen(obj) === true);
+
+// A partir d'ara qualsevol canvi fallarà
+obj.foo = 'quux'; // falla silenciosament
+obj.quaxxor = 'the friendly duck'; // romàn en silenci i no afegeix la propietat
+
+// ...i en mode estricte qualsevol intent llençarà una excepció TypeError
+function fail(){
+  'use strict';
+  obj.foo = 'sparky'; // llença TypeError
+  delete obj.quaxxor; // llença TypeError
+  obj.sparky = 'arf'; // llença TypeError
+}
+
+fail();
+
+// Intentar realitzar canvis a través de Object.defineProperty també resultaran en excepcions
+Object.defineProperty(obj, 'ohai', { value: 17 }); // llença TypeError
+Object.defineProperty(obj, 'foo', { value: 'eit' }); // llença TypeError
+
+ +

L'exemple següent demostra que valors de tipus objecte pertanyents a propietats d'un objecte congelat sí que es poden modificar.(freeze no s'aplica de manera recursiva).

+ +
obj1 = {
+  internal: {}
+};
+
+Object.freeze(obj1);
+obj1.internal.a = 'aValue';
+
+obj1.internal.a // 'aValue'
+
+// Per a fer que obj sigui totalment immutable cal congelar tots els objectes referenciats per aquest.
+// Per a aconseguir això utilitzem la funció següent
+function deepFreeze(obj) {
+
+  // Obté els nomes de les propietats definides a l'objecte obj
+  var propNames = Object.getOwnPropertyNames(obj);
+
+  // Congela les propietats abans de congelar l'objecte en si
+  propNames.forEach(function(name) {
+    var prop = obj[name];
+
+    // Congela prop si aquest és un objecte
+    if (typeof prop == 'object' && !Object.isFrozen(prop))
+      deepFreeze(prop);
+  });
+
+  // Congela l'objecte pare
+  return Object.freeze(obj);
+}
+
+obj2 = {
+  internal: {}
+};
+
+deepFreeze(obj2);
+obj2.internal.a = 'anotherValue';
+obj2.internal.a; // undefined
+
+ +

Notes

+ +

A l'EcmaScript 5, si l'argument passat a aquest mètode no és un objecte (un valor primitiu), llençarà un {{jsxref("TypeError")}}. A l'EcmaScript 6, un argument que no sigui un objecte serà tractat com si fós un objecte congelat ordinari, i simplement el retornarà.

+ +
> Object.freeze(1)
+TypeError: 1 no és un objecte // Codi EcmaScript 5
+
+> Object.freeze(1)
+1                             // Codi EcmaScript 6
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacionsEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.9', 'Object.freeze')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.freeze', 'Object.freeze')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Suport bàsic{{CompatGeckoDesktop("2")}}{{CompatChrome("6")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5.1")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaFirefox Mobile (Gecko)AndroidIE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/getprototypeof/index.html b/files/ca/web/javascript/reference/global_objects/object/getprototypeof/index.html new file mode 100644 index 0000000000..01666d0898 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/getprototypeof/index.html @@ -0,0 +1,124 @@ +--- +title: Object.getPrototypeOf() +slug: Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf +translation_of: Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf +--- +
{{JSRef}}
+ +

El mètode Object.getPrototypeOf() retorna el prototipus (és a dir, el valor de la propietat interna [[Prototype]]) de l'objecte especificat.

+ +

Sintaxi

+ +
Object.getPrototypeOf(obj)
+ +

Paràmetres

+ +
+
obj
+
L'objecte del qual es retornarà el prototipus.
+
+ +

Exemples

+ +
var proto = {};
+var obj = Object.create(proto);
+Object.getPrototypeOf(obj) === proto; // true
+
+ +

Notes

+ +

A l'EcmaScript 5 llençarà una excepció {{jsxref("TypeError")}} si el paràmetre obj no és un objecte. A l'EcmaScript 6 el paràmetre serà forçat al tipus {{jsxref("Object")}}.

+ +
Object.getPrototypeOf("foo");
+// TypeError: "foo" no és un objecte (codi EcmaScript 5)
+Object.getPrototypeOf("foo");
+// String.prototype                  (codi EcmaScript 6)
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.2', 'Object.getPrototypeOf')}}{{Spec2('ES5.1')}}Definició inicial.
{{SpecName('ES6', '#sec-object.getprototypeof', 'Object.getProtoypeOf')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("5")}}{{CompatGeckoDesktop("1.9.1")}}{{CompatIE("9")}}{{CompatOpera("12.10")}}{{CompatSafari("5")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Notes específiques per a Opera

+ +

Tot i que versions antigues de Opera no suporten Object.getPrototypeOf(), Opera soporta la propietat no standard {{jsxref("Object.proto", "__proto__")}} a partir de la versió 10.50.

+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/index.html b/files/ca/web/javascript/reference/global_objects/object/index.html new file mode 100644 index 0000000000..1c2a779065 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/index.html @@ -0,0 +1,213 @@ +--- +title: Object +slug: Web/JavaScript/Reference/Global_Objects/Object +tags: + - Constructor + - JavaScript + - NeedsTranslation + - Object + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/Object +--- +
{{JSRef}}
+ +

El constructor Object crea un embolcall d'objecte.

+ +

Sintaxi

+ +
// Inicialitzador d'objecte o literal
+{ [ parellNomValor1[, parellNomValor2[, ...parellNomValorN] ] ] }
+
+// Cridat com a constructor
+new Object([valor])
+ +

Paràmetres

+ +
+
parellNomValor1, parellNomValor2, ... parellNomValorN
+
Parells de noms (string) i valors (quasevol valor) on els noms se separen dels valors mitjançant dos punts (:).
+
value
+
Qualsevol valor.
+
+ +

Descripció

+ +

El constructor Object crea un embolcall d'objecte per al valor donat. Si el valor és {{jsxref("null")}} o bé {{jsxref("undefined")}}, crearà i retornarà un objecte buit. En cas contrari retornarà un objecte del tipus corresponent al valor donat. Si el valor donat ja és un objecte, retornarà el mateix objecte.

+ +

Quan es crida fora d'un contexte constructor, Object es comporta exactament de la mateixa manera que new Object().

+ +

Vegeu també la sintaxi literal / d'inicialització d'objectes.

+ +

Propietats del constructor Object

+ +
+
Object.length
+
Val 1.
+
{{jsxref("Object.prototype")}}
+
Permet l'adició de propietats a tots els objecte del tipus Object.
+
+ +

Mètodes del constructor Object

+ +
+
{{jsxref("Object.assign()")}} {{experimental_inline}}
+
Crea un nou objecte copiant els valors de totes les propietats pròpies enumerables d'un o més objectes origin a l'objecte destí.
+
{{jsxref("Object.create()")}}
+
Crea un nou objecte amb l'objecte prototipus que s'especifiqui, així com les propietats passades.
+
{{jsxref("Object.defineProperty()")}}
+
Afegeix a l'objecte la propietat amb nom descrita pel descriptor especificat.
+
{{jsxref("Object.defineProperties()")}}
+
Afegeix a l'objecte les propietats amb nom descrites pels descriptors especificats.
+
{{jsxref("Object.freeze()")}}
+
Congela un objecte de forma que les propietats d'aquest no poden ser esborrades o canviades.
+
{{jsxref("Object.getOwnPropertyDescriptor()")}}
+
Retorna un descriptor de propietat per a la propietat donada d'un objecte.
+
{{jsxref("Object.getOwnPropertyNames()")}}
+
Retorna un array que contindrà els nomes de totes les propietats pròpies d'un objecte, tant enumerables com no enumerables.
+
{{jsxref("Object.getOwnPropertySymbols()")}} {{experimental_inline}}
+
Retorna un array amb totes les propietats de tipus symbol que siguin pròpies d'un objecte donat.
+
{{jsxref("Object.getPrototypeOf()")}}
+
Retorna el prototipus de l'objecte especificat.
+
{{jsxref("Object.is()")}} {{experimental_inline}}
+
Compara dos valors i determina si són equivalents (és a dir, si són el mateix objecte).
+
{{jsxref("Object.isExtensible()")}}
+
Determina si és permés extendre un objecte.
+
{{jsxref("Object.isFrozen()")}}
+
Determina si l'objecte està congelat.
+
{{jsxref("Object.isSealed()")}}
+
Determina si un objecte està segellat.
+
{{jsxref("Object.keys()")}}
+
Retorna un array que conté els noms de totes les propietats enumerables pròpies d'un objecte donat.
+
{{jsxref("Object.observe()")}} {{experimental_inline}}
+
Observa canvies en un objecte de forma asíncrona.
+
{{jsxref("Object.preventExtensions()")}}
+
Desactiva la capacitat d'un objecte per a ser extés.
+
{{jsxref("Object.seal()")}}
+
Desactiva la capacitat de poder esborrar propietats de l'objecte.
+
{{jsxref("Object.setPrototypeOf()")}} {{experimental_inline}}
+
Assigna el prototipus (és a dir, la propietat interna [[Prototype]])
+
+ +

Instàncies de Object i l'objecte prototipus

+ +

A JavaScript, tots els objectes són descendents de Object; tots els objectes hereten els mètodes i propietats de {{jsxref("Object.prototype")}}, tot i que poden ser sobreescrits. Per exemple, els prototipus d'altres constructors sobreescriuen la propietat constructor i ofereixen el seu propi mètode toString(). Els canvis al prototipus Object es propaguen a tots els objectes a no ser que les propietats i mètodes que reben aquests canvis hagin sigut sobreescrites més avall a la cadena de prototipus.

+ +

Propietats

+ +
{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}
+ +

Mètodes

+ +
{{page('/ca/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}
+ +

Exemples

+ +

Utilitzar Object amb els tipus undefined i null types

+ +

Els següents exemples emmagatzemen un objecte Object buit a o:

+ +
var o = new Object();
+
+ +
var o = new Object(undefined);
+
+ +
var o = new Object(null);
+
+ +

Utilitzar Object per a crear objectes booleans

+ +

Els exemples següents emmagatzemen objectes de tipus {{jsxref("Boolean")}} a o:

+ +
// equivalent a o = new Boolean(true);
+var o = new Object(true);
+
+ +
// equivalent a o = new Boolean(false);
+var o = new Object(Boolean());
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.2', 'Object')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-object-objects', 'Object')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/isextensible/index.html b/files/ca/web/javascript/reference/global_objects/object/isextensible/index.html new file mode 100644 index 0000000000..7b8700654c --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/isextensible/index.html @@ -0,0 +1,138 @@ +--- +title: Object.isExtensible() +slug: Web/JavaScript/Reference/Global_Objects/Object/isExtensible +translation_of: Web/JavaScript/Reference/Global_Objects/Object/isExtensible +--- +
{{JSRef}}
+ +

El mètode Object.isExtensible() determina si un objecte és extensible (és a dir, si accepta l'addició de noves propietats).

+ +

Sintaxi

+ +
Object.isExtensible(obj)
+ +

Paràmetres

+ +
+
obj
+
L'objecte del que comprovarà l'extensibilitat.
+
+ +

Descripció

+ +

Per defecte tots els objectes són extensibles: se'ls hi poden afegir noves propietats, i (en objectes que suportin {{jsxref("Object.proto", "__proto__")}} {{deprecated_inline}} la seva propietat __proto__ property) es pot modificar. Es pot marcar un objecte com a no extensible utilitzant {{jsxref("Object.preventExtensions()")}}, {{jsxref("Object.seal()")}}, o bé {{jsxref("Object.freeze()")}}.

+ +

Exemples

+ +
// Els objectes nous són extensibles.
+var empty = {};
+Object.isExtensible(empty); // === true
+
+// ...pero això pot canviar.
+Object.preventExtensions(empty);
+Object.isExtensible(empty); // === false
+
+// Els objectes segellats són no extensibles per definició
+var sealed = Object.seal({});
+Object.isExtensible(sealed); // === false
+
+// Els objectes congelats també són no extensibes per definició
+var frozen = Object.freeze({});
+Object.isExtensible(frozen); // === false
+
+ +

Notes

+ +

A l'EcmaScript 5, si l'argument d'aquest mètode no és un objecte (un valor primitiu) es llençarà una excepció {{jsxref("TypeError")}}. A l'EcmaScript 6, un argument que no sigui un objecte es tractarà com si fós un objecte no extensible ordinari i simplement retornarà false.

+ +
Object.isExtensible(1);
+// TypeError: 1 no és un objecte (codi EcmaScript 5)
+
+Object.isExtensible(1);
+// false                         (codi EcmaScript 6)
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.13', 'Object.isExtensible')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.isextensible', 'Object.isExtensible')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("6")}}{{CompatGeckoDesktop("2.0")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5.1")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/isfrozen/index.html b/files/ca/web/javascript/reference/global_objects/object/isfrozen/index.html new file mode 100644 index 0000000000..46c2e24be2 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/isfrozen/index.html @@ -0,0 +1,182 @@ +--- +title: Object.isFrozen() +slug: Web/JavaScript/Reference/Global_Objects/Object/isFrozen +translation_of: Web/JavaScript/Reference/Global_Objects/Object/isFrozen +--- +
{{JSRef}}
+ +

El mètode Object.isFrozen() determina si un objecte està congelat.

+ +

Sintaxi

+ +
Object.isFrozen(obj)
+ +

Paràmetres

+ +
+
obj
+
L'objecte que es comprovarà si està congelat o no.
+
+ +

Descripció

+ +

Un objecte està congelat si i només si no és {{jsxref("Object.isExtensible()", "extensible", "", 1)}}, cap de les seves propietats és configurable, i cap de les seves propietats de dades (és a dir, propietats que no són accessor amb components getter o setter) that is, properties which are not accessor properties with getter or setter components) es poden escriure (modificar el seu valor).

+ +

Exemples

+ +
// Els objectes nous són extensibles, així que no estan congelats.
+Object.isFrozen({}); // === false
+
+// Un objecte buit que no és extensible està congelat ja que no te propietats que trenquin les restriccions.
+var vacuouslyFrozen = Object.preventExtensions({});
+Object.isFrozen(vacuouslyFrozen); // === true
+
+// Un objecte nou amb una propietat és extensible, i per tant no està congelat.
+var oneProp = { p: 42 };
+Object.isFrozen(oneProp); // === false
+
+// Fer-lo no extensible no el fa congelat,
+// perquè la propietat encara és configurable (i permet l'escriptura).
+Object.preventExtensions(oneProp);
+Object.isFrozen(oneProp); // === false
+
+// ...però, un altre cop, si eliminem la propietat ens trobem amb un objecte buit congelat.
+delete oneProp.p;
+Object.isFrozen(oneProp); // === true
+
+// Un objecte no extensible amb una propietat que no permeti l'escriptura però sí que es configurable no està congelat.
+var nonWritable = { e: 'plep' };
+Object.preventExtensions(nonWritable);
+Object.defineProperty(nonWritable, 'e', { writable: false }); // fer que la propietat no permeti l'escriptura
+Object.isFrozen(nonWritable); // === false
+
+// Fer aquesta propietat no configurable fa que l'objecte estigui congelat
+Object.defineProperty(nonWritable, 'e', { configurable: false }); // fer la propietat no configurable
+Object.isFrozen(nonWritable); // === true
+
+// Un objecte no extensible amb una propietat no configurable però que si permeti l'escriptura tampoc està congelat.
+var nonConfigurable = { release: 'the kraken!' };
+Object.preventExtensions(nonConfigurable);
+Object.defineProperty(nonConfigurable, 'release', { configurable: false });
+Object.isFrozen(nonConfigurable); // === false
+
+// Canviar aquesta propietat per a que no permeti l'escriptura fa que l'objecte estigui congelat.
+Object.defineProperty(nonConfigurable, 'release', { writable: false });
+Object.isFrozen(nonConfigurable); // === true
+
+// Un objecte amb una propietat accessor no extensible no està congelat.
+var accessor = { get food() { return 'yum'; } };
+Object.preventExtensions(accessor);
+Object.isFrozen(accessor); // === false
+
+// ...però si la propietat es fa no configurable l'objecte esdevé congelat.
+Object.defineProperty(accessor, 'food', { configurable: false });
+Object.isFrozen(accessor); // === true
+
+// La forma més fàcil, però, d'aconseguir congelar un objecte és cridant el mètode Object.freeze al mateix objecte.
+var frozen = { 1: 81 };
+Object.isFrozen(frozen); // === false
+Object.freeze(frozen);
+Object.isFrozen(frozen); // === true
+
+// Per definició, un objecte congelat no és extensible.
+Object.isExtensible(frozen); // === false
+
+// També per definició, un objecte congelat està segellat.
+Object.isSealed(frozen); // === true
+
+ +

Notes

+ +

A l'EcmaScript 5, si l'argument passat a aquest mètode no és un objecte (un valor primitiu), llençarà un TypeError. A l'EcmaScript 6, un argument que no sigui un objecte serà tractat com si fós un objecte congelat ordinari, i simplement el retornarà.

+ +
Object.isFrozen(1);
+// TypeError: 1 no és un objecte (codi EcmaScript 5)
+
+Object.isFrozen(1);
+// true                          (codi EcmaScript 6)
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.12', 'Object.isFrozen')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.isfrozen', 'Object.isFrozen')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("6")}}{{CompatGeckoDesktop("2.0")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5.1")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/keys/index.html b/files/ca/web/javascript/reference/global_objects/object/keys/index.html new file mode 100644 index 0000000000..17d05b181c --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/keys/index.html @@ -0,0 +1,189 @@ +--- +title: Object.keys() +slug: Web/JavaScript/Reference/Global_Objects/Object/keys +translation_of: Web/JavaScript/Reference/Global_Objects/Object/keys +--- +
{{JSRef}}
+ +

El mètode Object.keys() retorna un array de les propietats enumerables pròpies de l'objecte, en el mateix ordre en que es donarien en un bucle {{jsxref("Statements/for...in", "for...in")}} (la diferència radica en que el bucle for-in també enumera les propietats que pertanyen a la cadena de prototipus).

+ +

Sintaxi

+ +
Object.keys(obj)
+ +

Paràmetres

+ +
+
obj
+
L'objecte del qual es retornaran les seves propietats pròpies enumerables.
+
+ +

Descripció

+ +

Object.keys() retorna un array els elements del qual són strings que corresponen a les propietats enumerables que pertanyen directament a l'objecte obj. L'ordre de les propietats és el mateix que el donat per recòrrer les propieats de l'objecte de forma manual.

+ +

Exemples

+ +
var arr = ['a', 'b', 'c'];
+console.log(Object.keys(arr)); // console: ['0', '1', '2']
+
+// objecte en forma d'array
+var obj = { 0: 'a', 1: 'b', 2: 'c' };
+console.log(Object.keys(obj)); // console: ['0', '1', '2']
+
+// objecte en forma d'array amb les claus ordenades de manera aleatòria
+var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
+console.log(Object.keys(an_obj)); // console: ['2', '7', '100']
+
+// getFoo és una propietat no enumerable
+var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } });
+my_obj.foo = 1;
+
+console.log(Object.keys(my_obj)); // console: ['foo']
+
+ +

Si esteu interessats en obtenir totes les propietats, no només les enumerables, vegeu {{jsxref("Object.getOwnPropertyNames()")}}.

+ +

Notes

+ +

A l'EcmaScript 5 llençarà una excepció TypeError si el paràmetre obj no és un objecte. A l'EcmaScript 6 el paràmetre serà forçat al tipus Object.

+ +
Object.keys("foo");
+// TypeError: "foo" no és un objecte (codi EcmaScript 5)
+Object.keys("foo");
+// ["0", "1", "2"]                   (codi EcmaScript 6)
+
+ +

Polyfill

+ +

Per a afegit una funció compatible amb Object.keys en plataformes que no la suporten de forma nativa, podeu utilitzar el codi següent:

+ +
// Tret de https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
+if (!Object.keys) {
+  Object.keys = (function() {
+    'use strict';
+    var hasOwnProperty = Object.prototype.hasOwnProperty,
+        hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
+        dontEnums = [
+          'toString',
+          'toLocaleString',
+          'valueOf',
+          'hasOwnProperty',
+          'isPrototypeOf',
+          'propertyIsEnumerable',
+          'constructor'
+        ],
+        dontEnumsLength = dontEnums.length;
+
+    return function(obj) {
+      if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
+        throw new TypeError('Object.keys called on non-object');
+      }
+
+      var result = [], prop, i;
+
+      for (prop in obj) {
+        if (hasOwnProperty.call(obj, prop)) {
+          result.push(prop);
+        }
+      }
+
+      if (hasDontEnumBug) {
+        for (i = 0; i < dontEnumsLength; i++) {
+          if (hasOwnProperty.call(obj, dontEnums[i])) {
+            result.push(dontEnums[i]);
+          }
+        }
+      }
+      return result;
+    };
+  }());
+}
+
+ +

Cal destacar que aquest codi inclou també propietats no enumerables a Internet Explorer 7 (i possiblement també a Internet Explorer 8), al passar un objecte pertanyent a una altra finestra.

+ +

Per a una versió simplificada Polyfill per a navegadors vegeu Compatibilitat de navegadors amb la funció Object.keys de JavaScript.

+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.14', 'Object.keys')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a 1.8.5.
{{SpecName('ES6', '#sec-object.keys', 'Object.keys')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("5")}}{{CompatGeckoDesktop("2.0")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/observe/index.html b/files/ca/web/javascript/reference/global_objects/object/observe/index.html new file mode 100644 index 0000000000..7059b86cd8 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/observe/index.html @@ -0,0 +1,191 @@ +--- +title: Object.observe() +slug: Web/JavaScript/Reference/Global_Objects/Object/observe +translation_of: Archive/Web/JavaScript/Object.observe +--- +
{{JSRef}}
+ +

El mètode Object.observe() s'utilitza per observar asincrònicament els canvis en un objecte. Proveeix una corrent de canvis en l'ordre en què es produeixen.

+ +

Sintaxi

+ +
Object.observe(obj, callback[, acceptList])
+ +

Paràmetres

+ +
+
obj
+
L'objecte que s'observa.
+
callback
+
La funció es crida cada cop que es realitzen canvis, amb l'argument següent: +
+
changes
+
Un array d'objectes cadascún d'ells representa un canvi. Les propietats d'aquests objectes canvi són: +
    +
  • name: El nom de la propietat que s'ha canviat.
  • +
  • object: L'objecte canviat després d'haverse realitzat els canvis.
  • +
  • type: Una cadena que indica el tipus de canvi que s'ha portat a terme: "add", "update", o "delete".
  • +
  • oldValue: Només pels tipus "update" i "delete". El valor abans del canvi.
  • +
+
+
+
+
acceptList
+
La llista de tipus de canvis que s'han d'observar en l'objecte donat  callback. En cas d'ometre's, s'utilitzarà l'array ["add", "update", "delete", "reconfigure", "setPrototype", "preventExtensions"].
+
+ +

Descripció

+ +

callback és cridat cada cop que es realitza un canvi a obj, amb un array de tots els canvis en l'ordre en que han succeït.

+ +

Exemples

+ +

Mostrant tots els sis tipus diferents

+ +
var obj = {
+  foo: 0,
+  bar: 1
+};
+
+Object.observe(obj, function(changes) {
+  console.log(changes);
+});
+
+obj.baz = 2;
+// [{name: 'baz', object: <obj>, type: 'add'}]
+
+obj.foo = 'hello';
+// [{name: 'foo', object: <obj>, type: 'update', oldValue: 0}]
+
+delete obj.baz;
+// [{name: 'baz', object: <obj>, type: 'delete', oldValue: 2}]
+
+Object.defineProperty(obj, 'foo', {writable: false});
+// [{name: 'foo', object: <obj>, type: 'reconfigure'}]
+
+Object.setPrototypeOf(obj, {});
+// [{name: '__proto__', object: <obj>, type: 'setPrototype', oldValue: <prototype>}]
+
+Object.seal(obj);
+// [
+//   {name: 'foo', object: <obj>, type: 'reconfigure'},
+//   {name: 'bar', object: <obj>, type: 'reconfigure'},
+//   {object: <obj>, type: 'preventExtensions'}
+// ]
+
+ +

Enllaçar dades

+ +
// Un model d'usuari
+var user = {
+  id: 0,
+  name: 'Brendan Eich',
+  title: 'Mr.'
+};
+
+// Crear una benvinguda per l'usuari
+function updateGreeting() {
+  user.greeting = 'Hello, ' + user.title + ' ' + user.name + '!';
+}
+updateGreeting();
+
+Object.observe(user, function(changes) {
+  changes.forEach(function(change) {
+    // Qualsevol canvi de nom del temps o títol, actualitzar la benvinguda
+    if (change.name === 'name' || change.name === 'title') {
+      updateGreeting();
+    }
+  });
+});
+
+ +

Tipus de canvi personalitzat

+ +
// Un punt en un pla 2D
+var point = {x: 0, y: 0, distance: 0};
+
+function setPosition(pt, x, y) {
+  // Performing a custom change
+  Object.getNotifier(pt).performChange('reposition', function() {
+    var oldDistance = pt.distance;
+    pt.x = x;
+    pt.y = y;
+    pt.distance = Math.sqrt(x * x + y * y);
+    return {oldDistance: oldDistance};
+  });
+}
+
+Object.observe(point, function(changes) {
+  console.log('Distance change: ' + (point.distance - changes[0].oldDistance));
+}, ['reposition']);
+
+setPosition(point, 3, 4);
+// Distance change: 5
+
+ +

Especificacions

+ +

Proposta de Strawman per ECMAScript 7.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("36")}}{{CompatNo}} [1]{{CompatNo}} [2]{{CompatOpera("23")}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatChrome("36")}}{{CompatNo}} [1]{{CompatNo}} [2]{{CompatOpera("23")}}{{CompatNo}}
+
+ +

[1]: Vegeu {{bug(800355)}}

+ +

[2]: Vegeu rellevant entrada de l'estat de la plataforma MS Edge

+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/object/prototype/index.html b/files/ca/web/javascript/reference/global_objects/object/prototype/index.html new file mode 100644 index 0000000000..b18ecc2d5a --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/object/prototype/index.html @@ -0,0 +1,214 @@ +--- +title: Object.prototype +slug: Web/JavaScript/Reference/Global_Objects/Object/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Object +--- +
{{JSRef}}
+ +

La propietat Object.prototype representa el prototipus per a {{jsxref("Object")}}.

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

A JavaScript, tots els objectes hereten de {{jsxref("Object")}}; tots els objectes hereten els mètodes i propietats de Object.prototype, tot i que es poden sobreescriure (excepte un Object amb prototipus null, és a dir, Object.create(null)). Per exemple, altres prototipus de constructors sobreescriuen la propietat constructor i ofereixen els seus propis mètodes {{jsxref("Object.prototype.toString()", "toString()")}}. Els canvis al prototipus Object es propaguen a tots els objectes a no ser que les propietats i mètodes que reben aquests canvis hagin sigut sobreescrites més avall a la cadena de prototipus.

+ +

Propietats

+ +
+
{{jsxref("Object.prototype.constructor")}}
+
Especifica la funció que ha creat el prototipus de l'objecte.
+
{{jsxref("Object.prototype.__proto__")}} {{non-standard_inline}}
+
Referencia l'objecte utilitzat com a prototipus quan aquest objecte va ser instanciat.
+
{{jsxref("Object.prototype.__noSuchMethod__")}} {{non-standard_inline}}
+
Permet definir una funció que serà executada quan es cridi com mètode un membre no definit.
+
{{jsxref("Object.prototype.__count__")}} {{obsolete_inline}}
+
Retornava el nombre de propietats enumerables que hi hagués a un objecte definit per l'usuari. S'ha eliminat.
+
{{jsxref("Object.prototype.__parent__")}} {{obsolete_inline}}
+
Referenciava el context d'un objecte. S'ha eliminat.
+
+ +

Mètodes

+ +
+
{{jsxref("Object.prototype.__defineGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}
+
Associa una funció a una propietat que, quan s'accedeix, executa aquesta funció i retorna el seu valor.
+
{{jsxref("Object.prototype.__defineSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}
+
Associa una funció a una propietat que, quan s'assigna, executa aquesta funció que modifica la propietat.
+
{{jsxref("Object.prototype.__lookupGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}
+
Retorna una funció associada a la propietat especificada pel mètode {{jsxref("Object.defineGetter", "__defineGetter__")}}.
+
{{jsxref("Object.prototype.__lookupSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}
+
Retorna a funció associada a la propietat especificada pel mètode {{jsxref("Object.defineSetter", "__defineSetter__")}}.
+
{{jsxref("Object.prototype.hasOwnProperty()")}}
+
Retorna un booleà que indica si l'objecte conté la propietat especificada com una propietat pròpia d'ell mateix en comptes d'heretar-la a través de la cadena de prototipus.
+
{{jsxref("Object.prototype.isPrototypeOf()")}}
+
Retorna un booleà que indica si l'objecte espeicfifcat pertany a la cadena de prototipus de l'objecte sobre el que es crida aquest mètode.
+
{{jsxref("Object.prototype.propertyIsEnumerable()")}}
+
Retorna un booleà que indica si està activat l'atribut intern DontEnum de l'ECMAScript.
+
{{jsxref("Object.prototype.toSource()")}} {{non-standard_inline}}
+
Retorna un string que conté cofi font que defineix un literal d'objecte que representa l'objecte sobre el que s'executa aquest mètode; aquest valor pot utilitzar-se per a crear un nou objecte.
+
{{jsxref("Object.prototype.toLocaleString()")}}
+
Crida el mètode {{jsxref("Object.toString", "toString()")}}.
+
{{jsxref("Object.prototype.toString()")}}
+
Retorna una representació d'aquest objecte en forma de string.
+
{{jsxref("Object.prototype.unwatch()")}} {{non-standard_inline}}
+
Esborra un watchpoint d'una propietat de l'objecte.
+
{{jsxref("Object.prototype.valueOf()")}}
+
Retorna el valor primitiu de l'objecte especificat.
+
{{jsxref("Object.prototype.watch()")}} {{non-standard_inline}}
+
Afegeix un watchpoint a una propietat de l'objecte.
+
{{jsxref("Object.prototype.eval()")}} {{obsolete_inline}}
+
Evaluava un string de codi font JavaScript dins el context de l'objecte especificat. S'ha eliminat.
+
+ +

Exemples

+ +

Degut a que JavaScript no res semblant a subclasses d'objectes, la propietat prototype és una bona forma d'utilitzar algunes funcions que fan d'objectes com a "classe base". Per exemple:

+ +
var Person = function() {
+  this.canTalk = true;
+};
+
+Person.prototype.greet = function() {
+  if (this.canTalk) {
+    console.log('Hi, I am ' + this.name);
+  }
+};
+
+var Employee = function(name, title) {
+  Person.call(this);
+  this.name = name;
+  this.title = title;
+};
+
+Employee.prototype = Object.create(Person.prototype);
+Employee.prototype.constructor = Employee;
+
+Employee.prototype.greet = function() {
+  if (this.canTalk) {
+    console.log('Hi, I am ' + this.name + ', the ' + this.title);
+  }
+};
+
+var Customer = function(name) {
+  Person.call(this);
+  this.name = name;
+};
+
+Customer.prototype = Object.create(Person.prototype);
+Customer.prototype.constructor = Customer;
+
+var Mime = function(name) {
+  Person.call(this);
+  this.name = name;
+  this.canTalk = false;
+};
+
+Mime.prototype = Object.create(Person.prototype);
+Mime.prototype.constructor = Mime;
+
+var bob = new Employee('Bob', 'Builder');
+var joe = new Customer('Joe');
+var rg = new Employee('Red Green', 'Handyman');
+var mike = new Customer('Mike');
+var mime = new Mime('Mime');
+
+bob.greet();
+// Hi, I am Bob, the Builder
+
+joe.greet();
+// Hi, I am Joe
+
+rg.greet();
+// Hi, I am Red Green, the Handyman
+
+mike.greet();
+// Hi, I am Mike
+
+mime.greet();
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.2.3.1', 'Object.prototype')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-object.prototype', 'Object.prototype')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

 Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/clear/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/clear/index.html new file mode 100644 index 0000000000..443e075d46 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/clear/index.html @@ -0,0 +1,91 @@ +--- +title: WeakMap.prototype.clear() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/clear +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/clear +--- +
{{JSRef}} {{obsolete_header}}
+ +

El mètode clear() elimina tots els elements d'un objecte WeakMap.

+ +

Sintaxi

+ +
wm.clear();
+ +

Exemples

+ +

Utilitzar el mètode clear

+ +
var wm = new WeakMap();
+var obj = {};
+
+wm.set(obj, "foo");
+wm.set(window, "bar");
+
+wm.has(obj); // true
+wm.has(window); // true
+
+wm.clear();
+
+wm.has(obj)  // false
+wm.has(window)  // false
+
+ +

Especificacions

+ +

No forma part de cap especificació o borrador actual. Aquest mètode formava part del borrador de l'especificació d'ECMAScript 6 fins a la revisió número 28 (versió del 14 d'octubre del 2014), però s'ha eliminat en versions posteriors del borrador. No formarà part de l'estàndard final.

+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("20.0")}}11237.1
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile("20.0")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/delete/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/delete/index.html new file mode 100644 index 0000000000..1037fdb3fc --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/delete/index.html @@ -0,0 +1,114 @@ +--- +title: WeakMap.prototype.delete() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/delete +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/delete +--- +
{{JSRef}}
+ +

El mètode delete() elimina l'element especificat d'un objecte WeakMap.

+ +

Sintaxi

+ +
wm.delete(key);
+ +

Parameters

+ +
+
key
+
Necessari. La clau de l'element a eliminar de l'objecte WeakMap.
+
+ +

Valor de retorn

+ +

Retorna true si un element en l'objecte WeakMap s'ha eliminat satisfactòriament.

+ +

Exemples

+ +

Utilitzarel mètode delete

+ +
var wm = new WeakMap();
+wm.set(window, "foo");
+
+wm.delete(window); // Retorna true. Eliminat satisfactòriament
+
+wm.has(window);    // Retorna false. L'objecte window ja no es troba en el WeakMap.
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap.prototype.delete', 'WeakMap.prototype.delete')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11237.1
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Notes específiques per a Firefox

+ + + +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/get/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/get/index.html new file mode 100644 index 0000000000..f69ca1aa58 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/get/index.html @@ -0,0 +1,115 @@ +--- +title: WeakMap.prototype.get() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/get +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/get +--- +
{{JSRef}}
+ +

El mètode get() retorna un element especificat d'un objecte WeakMap.

+ +

Sintaxi

+ +
wm.get(key);
+ +

Paràmetres

+ +
+
key
+
Necessari. La clau d'un element a retornar de l'objecte WeakMap.
+
+ +

Valor a retornar

+ +

Retorna l'element associat a la clau especificada o undefined si no es pot trobar la clau en l'objecte WeakMap.

+ +

Exemples

+ +

Utilitzar el mètode get

+ +
var wm = new WeakMap();
+wm.set(window, "foo");
+
+wm.get(window); // Retorna "foo".
+wm.get("baz");  // Retorna undefined.
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap.prototype.get', 'WeakMap.prototype.get')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11237.1
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Notes específiques per a Firefox

+ + + +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/has/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/has/index.html new file mode 100644 index 0000000000..0a2d017462 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/has/index.html @@ -0,0 +1,118 @@ +--- +title: WeakMap.prototype.has() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/has +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/has +--- +
{{JSRef}}
+ +

El mètode has() retorna un booleà indicant si un element amb una clau especificada existeix o no en l'objecte WeakMap.

+ +

Sintaxi

+ +
wm.has(key);
+ +

Paràmetres

+ +
+
key
+
Necessari. La clau de l'element a comprovar la seva presència de l'objecte WeakMap.
+
+ +

valor de retorn

+ +
+
Booleà
+
Retorna true si un element amb una clau especificada existeix en l'objecte WeakMap; en el cas contrari retornarà false.
+
+ +

Exemples

+ +

Utilitzar el mètode has

+ +
var wm = new WeakMap();
+wm.set(window, "foo");
+
+wm.has(window); // retorna true
+wm.has("baz");  // retorna false
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap.prototype.has', 'WeakMap.prototype.has')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11237.1
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Notes específiques per a Firefox

+ + + +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/index.html new file mode 100644 index 0000000000..27fdd6a71d --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/index.html @@ -0,0 +1,279 @@ +--- +title: WeakMap +slug: Web/JavaScript/Reference/Global_Objects/WeakMap +tags: + - ECMAScript6 + - Experimental + - JavaScript + - NeedsTranslation + - TopicStub + - WeakMap +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap +--- +
{{JSRef}}
+ +

L'objecte WeakMap és una col·lecció de parelles clau/valor on les claus són dèbilment referenciades. Les claus han de ser objectes i els valors poden ser valors aribitraris.

+ +

Sintaxi

+ +
new WeakMap([iterable])
+
+ +

Paràmetres

+ +
+
iterable
+
Iterable és un Array o un altre objecte iterable el qual els seus elements són parelles clau/valor (Array de 2 elements). Cada parella clau/valor serà afegida al nou WeakMap. null és tractat com a undefined.
+
+ +

Descripció

+ +

Les claus de WeakMaps són només de tipus Object. {{Glossary("Primitive", "Primitive data types")}} com a claus no són permesos (e.g. a {{jsxref("Symbol")}} no pot ser una clau WeakMap).

+ +

La clau d'un WeakMap es sostè dèbilment.  El que significa que, si no hi ha altres referències fortes a la clau, llavors la entrada sencera serà eliminada del WeakMap pel recol·lector de brossa (garbage collector).

+ +

Per què WeakMap?

+ +

El programador expert en JavaScript s'adonarà que aquesta API es podria implementar en JavaScript amb dos arrays (una per a claus, i una per valors) compartides pels quatre mètodes de l'API. Tal implementació tindria dos inconvenients principals. El primer és que la cerca té un cost de O(n) (on n és el nombre de claus al mapa). El segon és que té problemes de fuita de memòria (memory leak). Amb els mapes mantinguts manualment, l'array de claus mantindria referències a le objectes clau, evitant que aquests fóssin eliminats de memòria pel recol·lector de brossa. Als WeakMaps natius, les referències als objectes clau són "dèbils", que vol dir que el recol·lector de brossa pot eliminar l'objecte de memòria si aquest només és referenciat per referències dèbils.

+ +

Degut a que les referències són dèbils les claus del WeakMap no són enumerables (és a dir, no hi ha cap mètode que us retornarà un llistat de claus). Si aquest mètode existís, aquest dependria de l'estat del recol·lector de brossa, introduïnt un comportament no determinista. Si voleu tenir un llistat amb les claus, l'haureu de mantenir pel vostre compte.

+ +

Propietats

+ +
+
WeakMap.length
+
El valor de la propietat length és 0.
+
{{jsxref("WeakMap.prototype")}}
+
Representa el prototip pel constructor WeakMap. Permet l'adició de propietats a tots els objectes WeakMap.
+
+ +

Instàncies WeakMap

+ +

Totes les instàncies WeakMap hereten de {{jsxref("WeakMap.prototype")}}.

+ +

Propietats

+ +

{{page('ca/Web/JavaScript/Reference/Global_Objects/WeakMap/prototype','Properties')}}

+ +

Mètodes

+ +

{{page('ca/Web/JavaScript/Reference/Global_Objects/WeakMap/prototype','Methods')}}

+ +

Exemples

+ +

Utilitzar WeakMap

+ +
var wm1 = new WeakMap(),
+    wm2 = new WeakMap(),
+    wm3 = new WeakMap();
+var o1 = {},
+    o2 = function(){},
+    o3 = window;
+
+wm1.set(o1, 37);
+wm1.set(o2, "azerty");
+wm2.set(o1, o2); // un valor pot ser qualsevol cosa, incloent un objecte object o una funció
+wm2.set(o3, undefined);
+wm2.set(wm1, wm2); // claus i valors poden ser qualsevol objecte. Fins i tot WeakMaps!
+
+wm1.get(o2); // "azerty"
+wm2.get(o2); // undefined, ja que no hi ha cap valor per o2 a wm2
+wm2.get(o3); // undefined, al tenir assignat aquest valor
+
+wm1.has(o2); // true
+wm2.has(o2); // false
+wm2.has(o3); // true (encara que el valor en si sigui 'undefined')
+
+wm3.set(o1, 37);
+wm3.get(o1); // 37
+
+wm1.has(o1); // true
+wm1.delete(o1);
+wm1.has(o1); // false
+
+ +

Implementar una classe tipus WeakMap amb un mètode .clear()

+ +

Amb fins expositius, l'exemple següent utilitza el nou constructor class d' ECMAScript 6, el qual no està àmpliament implementat.

+ +
class ClearableWeakMap {
+  constructor(init) {
+    this._wm = new WeakMap(init)
+  }
+  clear() {
+    this._wm = new WeakMap()
+  }
+  delete(k) {
+    return this._wm.delete(k)
+  }
+  get(k) {
+    return this._wm.get(k)
+  }
+  has(k) {
+    return this._wm.has(k)
+  }
+  set(k, v) {
+    this._wm.set(k, v)
+    return this
+  }
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap-objects', 'WeakMap')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11{{ CompatOpera(23) }}7.1
new WeakMap(iterable)38{{CompatGeckoDesktop("36")}}{{CompatNo}}{{ CompatOpera(25) }}{{CompatNo}}
clear()36{{CompatGeckoDesktop("20.0")}}11{{ CompatOpera(23) }}7.1
Constructor argument: new WeakMap(null){{CompatVersionUnknown}}{{CompatGeckoDesktop("37")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
Monkey-patched set() in constructor{{CompatVersionUnknown}}{{CompatGeckoDesktop("37")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
WeakMap() without new throws{{CompatVersionUnknown}}{{CompatGeckoDesktop("42")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic35{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
new WeakMap(iterable)38{{CompatGeckoMobile("36")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
clear()35{{CompatGeckoMobile("20.0")}}{{CompatNo}}{{CompatNo}}8
Constructor argument: new WeakMap(null){{CompatUnknown}}{{CompatGeckoMobile("37")}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}
Monkey-patched set() in constructor{{CompatUnknown}}{{CompatGeckoMobile("37")}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}
WeakMap() without new throws{{CompatUnknown}}{{CompatGeckoMobile("42")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/prototype/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/prototype/index.html new file mode 100644 index 0000000000..5155a0a664 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/prototype/index.html @@ -0,0 +1,132 @@ +--- +title: WeakMap.prototype +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap +--- +
{{JSRef}}
+ +

La propietat WeakMap.prototype representa el prototip pel constructor {{jsxref("WeakMap")}}.

+ +
{{js_property_attributes(0,0,0)}}
+ +

Descripció

+ +

Les instantànies {{jsxref("WeakMap")}} hereten de {{jsxref("WeakMap.prototype")}}. Es pot utilitzar l'objecte prototip del constructor per afegir propietats o mètodes a totes les instàncies WeakMap.

+ +

WeakMap.prototype és en si mateix només un objecte ordinari:

+ +
Object.prototype.toString.call(WeakMap.prototype); // "[object Object]"
+ +

Propietats

+ +
+
WeakMap.prototype.constructor
+
Retorna la funció que ha creat un prototip de la instància. Aquesta és la funció {{jsxref("WeakMap")}} per defecte.
+
+ +

Mètodes

+ +
+
{{jsxref("WeakMap.delete", "WeakMap.prototype.delete(key)")}}
+
Elimina qualsevol valor associat a key. WeakMap.prototype.has(key) retornarà false després d'això.
+
{{jsxref("WeakMap.get", "WeakMap.prototype.get(key)")}}
+
Retorna el valor associat a key, o undefined si no n'hi ha cap.
+
{{jsxref("WeakMap.has", "WeakMap.prototype.has(key)")}}
+
Retorna un booleà afirmant si un valor s'ha associat o no a la key en l'objecte WeakMap.
+
{{jsxref("WeakMap.set", "WeakMap.prototype.set(key, value)")}}
+
Estableix el valor per la key en l'objecte WeakMap. Retorna l'objecte WeakMap.
+
{{jsxref("WeakMap.prototype.clear()")}} {{obsolete_inline}}
+
Elimina totes les parelles clau/valor de l'objecte WeakMap. Vegeu que es posible implementar un objecte WeakMap-like que tingui un mètode .clear() per mitjà d'encapsular un objecte WeakMap que no ho tingui (vegeu un exemple a la pàgina {{jsxref("WeakMap")}})
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap.prototype', 'WeakMap.prototype')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11237.1
Objecte ordinari{{CompatUnknown}}{{CompatGeckoDesktop("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
Objecte ordinari{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakmap/set/index.html b/files/ca/web/javascript/reference/global_objects/weakmap/set/index.html new file mode 100644 index 0000000000..800a097971 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakmap/set/index.html @@ -0,0 +1,120 @@ +--- +title: WeakMap.prototype.set() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/set +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/set +--- +
{{JSRef}}
+ +

El mètode set() afegeix un nou element amb una key i un value especificats a un objecte WeakMap.

+ +

Sintaxi

+ +
wm.set(key, value);
+ +

Paràmetres

+ +
+
key
+
Necesari. La clau de l'element a afegir al objecte WeakMap.
+
value
+
Necesari. El valor de l'element a afegir a l'objecte WeakMap.
+
+ +

Valor de retorn

+ +

L'objecte WeakMap.

+ +

Exemples

+ +

Utilitzar el mètode set

+ +
var wm = new WeakMap();
+var obj = {};
+
+// Afegir nous elements al WeakMap
+wm.set(obj, "foo").set(window, "bar"); // chainable
+
+// Actualitzem un element en WeakMap
+wm.set(obj, "baz");
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakmap.prototype.set', 'WeakMap.prototype.set')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop("6.0")}}11237.1
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile("6.0")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Notes específiques per a Firefox

+ + + +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/add/index.html b/files/ca/web/javascript/reference/global_objects/weakset/add/index.html new file mode 100644 index 0000000000..983b24329a --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/add/index.html @@ -0,0 +1,103 @@ +--- +title: WeakSet.prototype.add() +slug: Web/JavaScript/Reference/Global_Objects/WeakSet/add +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/add +--- +
{{JSRef}}
+ +

El mètode add() afegeix un nou objecte al final d'un objecte WeakSet.

+ +

Sintaxi

+ +
ws.add(value);
+ +

Paràmetres

+ +
+
value
+
Necessari. L'objecte que es vol afegir a la col·lecció de WeakSet.
+
+ +

Utilitzar el mètode add

+ +
var ws = new WeakSet();
+
+ws.add(window); // afegeix l'objecte window al WeakSet
+
+ws.has(window); // true
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakset.prototype.add', 'WeakSet.prototype.add')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop(34)}}{{CompatNo}}23{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/clear/index.html b/files/ca/web/javascript/reference/global_objects/weakset/clear/index.html new file mode 100644 index 0000000000..4e6b2e6f8c --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/clear/index.html @@ -0,0 +1,87 @@ +--- +title: WeakSet.prototype.clear() +slug: Web/JavaScript/Reference/Global_Objects/WeakSet/clear +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/clear +--- +
{{JSRef}} {{obsolete_header}}
+ +

El mètode clear() elimina tots els elements d'un objecte WeakSet.

+ +

Sintaxi

+ +
ws.clear();
+ +

Exemples

+ +

Utilitzar el mètode clear

+ +
var ws = new WeakSet();
+
+ws.add(window);
+ws.has(window);  // true
+
+ws.clear();
+
+ws.has(window); // false
+
+ +

Especificacions

+ +

No forma part de cap especificació actual o borrador. Aquest mètode formava part del borrador de l'especificació d'ECMAScript 6 fins la revisió 28 (versió del 14 d'octubre del 2014), però s'ha eliminat en versions posteriors del borrador. No formarà part de l'estàndard final.

+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop(34)}}{{CompatNo}}23{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoMobile(34)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/delete/index.html b/files/ca/web/javascript/reference/global_objects/weakset/delete/index.html new file mode 100644 index 0000000000..9bfaa0f439 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/delete/index.html @@ -0,0 +1,112 @@ +--- +title: WeakSet.prototype.delete() +slug: Web/JavaScript/Reference/Global_Objects/WeakSet/delete +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/delete +--- +
{{JSRef}}
+ +

El mètode delete()elimina l'element especificat de l'objecte WeakSet.

+ +

Sintaxi

+ +
ws.delete(value);
+ +

Paràmetres

+ +
+
value
+
Necessari. L'objecte que es vol eliminar de l'objecte WeakSet.
+
+ +

Return value

+ +

Retorna true si l'element dins l'objecte WeakSet s'ha eliminat satisfactòriament; Del cas contrari retornarà false.

+ +

Exemples

+ +

Utilitzar el mètode delete

+ +
var ws = new WeakSet();
+var obj = {};
+
+ws.add(window);
+
+ws.delete(obj);    // Retorna false. No s'ha trobat cap obj per eliminar.
+ws.delete(window); // Retorna true.  Eliminat satisfactòriament.
+
+ws.has(window);    // Retorna false. window ja no és present en WeakSet.
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakset.prototype.delete', 'WeakSet.prototype.delete')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop(34)}}{{CompatNo}}23{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/has/index.html b/files/ca/web/javascript/reference/global_objects/weakset/has/index.html new file mode 100644 index 0000000000..b2074a9847 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/has/index.html @@ -0,0 +1,113 @@ +--- +title: WeakSet.prototype.has() +slug: Web/JavaScript/Reference/Global_Objects/WeakSet/has +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/has +--- +
{{JSRef}}
+ +

El mètode has() retorna un booleà indicant si un objecte existeix o no en unmethod returns a boolean indicating whether an object exists in a WeakSet or not.

+ +

Sintaxi

+ +
ws.has(valor);
+ +

Paràmetres

+ +
+
valor
+
Necessari. L'objecte a comprovar la seva presència en WeakSet.
+
+ +

Valor de retorn

+ +
+
Booleà
+
Retorna true si un element amb el valor especificat existeix en l'objecte WeakSet; en el cas contrari retornarà false.
+
+ +

Exemples

+ +

Utilitzar el mètode has

+ +
var ws = new WeakSet();
+var obj = {};
+ws.add(window);
+
+mySet.has(window);  // retorna true
+mySet.has(obj);     // retorna false
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakset.prototype.has', 'WeakSet.prototype.has')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{CompatGeckoDesktop(34)}}{{CompatNo}}23{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/index.html b/files/ca/web/javascript/reference/global_objects/weakset/index.html new file mode 100644 index 0000000000..d1ae3999a6 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/index.html @@ -0,0 +1,201 @@ +--- +title: WeakSet +slug: Web/JavaScript/Reference/Global_Objects/WeakSet +tags: + - ECMAScript6 + - Experimental + - JavaScript + - NeedsTranslation + - TopicStub + - WeakSet +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet +--- +
{{JSRef}}
+ +

L'objecte WeakSet permet emmagatzemar dèbilment objects en una col·lecció.

+ +

Sintaxi

+ +
 new WeakSet([iterable]);
+ +

Paràmetres

+ +
+
iterable
+
Si es pasa un objecte iterable, tots els seus elements seràn afegits al nou WeakSet. null es tractat com a undefined.
+
+ +

Descripció

+ +

Els objectes WeakSet són col·leccions d'objectes. Un objecte al WeakSet només pot passar un cop, és únic en la col·lecció de WeakSet.

+ +

Les principals diferències respecte l'objecte {{jsxref("Set")}} són:

+ + + +

Propietats

+ +
+
WeakSet.length
+
El valor de la propietat length és 0.
+
{{jsxref("WeakSet.prototype")}}
+
Representa el prototip per al constructor de Set. Permet afegir propietats a tots els objectes WeakSet.
+
+ +

Instàncies WeakSet

+ +

Totes les instàncies WeakSet hereten de {{jsxref("WeakSet.prototype")}}.

+ +

Propietats

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/WeakSet/prototype','Properties')}}

+ +

Mètodes

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/WeakSet/prototype','Methods')}}

+ +

Exemples

+ +

Utilitzar l'objecte WeakSet

+ +
var ws = new WeakSet();
+var obj = {};
+var foo = {};
+
+ws.add(window);
+ws.add(obj);
+
+ws.has(window); // true
+ws.has(foo);    // false, foo no s'ha afegit al conjunt
+
+ws.delete(window); // elimina window del conjunt
+ws.has(window);    // false, window ha sigut eliminat
+
+ws.clear(); // buida tot el WeakSet
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakset-objects', 'WeakSet')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome(36)}}{{ CompatGeckoDesktop(34) }}{{CompatNo}}{{ CompatOpera(23) }}9
new WeakSet(iterable)38{{ CompatGeckoDesktop(34) }}{{CompatNo}}259
Constructor argument: new WeakSet(null){{CompatVersionUnknown}}{{CompatGeckoDesktop("37")}}{{CompatUnknown}}{{CompatUnknown}}9
Monkey-patched add() in Constructor{{CompatVersionUnknown}}{{CompatGeckoDesktop("37")}}{{CompatUnknown}}{{CompatUnknown}}9
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}9
new WeakMap(iterable){{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}9
Constructor argument: new WeakSet(null){{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}9
Monkey-patched add() in Constructor{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}9
+
+ +

Vegeu també

+ + diff --git a/files/ca/web/javascript/reference/global_objects/weakset/prototype/index.html b/files/ca/web/javascript/reference/global_objects/weakset/prototype/index.html new file mode 100644 index 0000000000..2b4cd51048 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/weakset/prototype/index.html @@ -0,0 +1,131 @@ +--- +title: WeakSet.prototype +slug: Web/JavaScript/Reference/Global_Objects/WeakSet/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet +--- +
{{JSRef}}
+ +

La propietat WeakSet.prototype representa el prototip pel constructor {{jsxref("WeakSet")}}.

+ +
{{js_property_attributes(0,0,0)}}
+ +

Descripció

+ +

Les instàncies {{jsxref("WeakSet")}} hereten de {{jsxref("WeakSet.prototype")}}. Es pot utilitzar l'objecte prototip del constructor per afegir propietats o mètodes a totes les instàncies WeakSet.

+ +

WeakSet.prototype és en si mateix només un objecte ordinari

+ +
Object.prototype.toString.call(WeakSet.prototype); // "[object Object]"
+ +

Propietats

+ +
+
WeakSet.prototype.constructor
+
Retorna la funció que ha creat un prototip de la instància. Aquesta és la funció {{jsxref("WeakSet")}} per defecte.
+
+ +

Mètodes

+ +
+
{{jsxref("WeakSet.add", "WeakSet.prototype.add(value)")}}
+
Afegeix un nou element amb el valor donat a l'objecte WeakSet.
+
{{jsxref("WeakSet.delete", "WeakSet.prototype.delete(value)")}}
+
Elimina l'element associat al value. WeakSet.prototype.has(value) retornarà després false.
+
{{jsxref("WeakSet.has", "WeakSet.prototype.has(value)")}}
+
Retorna un booleà afirmant si un element és o no present amb el valor donat en l'objecte WeakSet.
+
{{jsxref("WeakSet.prototype.clear()")}} {{obsolete_inline}}
+
Elimina tots els elements de l'objecte WeakSet.
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-weakset.prototype', 'WeakSet.prototype')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic36{{ CompatGeckoDesktop(34) }}{{CompatNo}}23{{CompatNo}}
Objecte ordinari{{CompatUnknown}}{{CompatGeckoDesktop("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracterísticaChrome per AndroidAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{ CompatGeckoMobile(34) }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
Objecte ordinari{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

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