From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../ca/web/javascript/reference/errors/index.html | 31 +++++++++ .../reference/errors/nomes-lectura/index.html | 78 ++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 files/ca/web/javascript/reference/errors/index.html create mode 100644 files/ca/web/javascript/reference/errors/nomes-lectura/index.html (limited to 'files/ca/web/javascript/reference/errors') diff --git a/files/ca/web/javascript/reference/errors/index.html b/files/ca/web/javascript/reference/errors/index.html new file mode 100644 index 0000000000..c295fccea6 --- /dev/null +++ b/files/ca/web/javascript/reference/errors/index.html @@ -0,0 +1,31 @@ +--- +title: JavaScript error reference +slug: Web/JavaScript/Reference/Errors +tags: + - Debugging + - Error + - Errors + - Exception + - JavaScript + - NeedsTranslation + - TopicStub + - exceptions +translation_of: Web/JavaScript/Reference/Errors +--- +

{{jsSidebar("Errors")}}

+ +

Below, you'll find a list of errors which are thrown by JavaScript. These errors can be a helpful debugging aid, but the reported problem isn't always immediately clear. The pages below will provide additional details about these errors. Each error is an object based upon the {{jsxref("Error")}} object, and has a name and a message.

+ +

Errors displayed in the Web console may include a link to the corresponding page below to help you quickly comprehend the problem in your code.

+ +

List of errors

+ +

In this list, each page is listed by name (the type of error) and message (a more detailed human-readable error message). Together, these two properties provide a starting point toward understanding and resolving the error. For more information, follow the links below!

+ +

{{ListSubPages("/en-US/docs/Web/JavaScript/Reference/Errors")}}

+ +

See also

+ + diff --git a/files/ca/web/javascript/reference/errors/nomes-lectura/index.html b/files/ca/web/javascript/reference/errors/nomes-lectura/index.html new file mode 100644 index 0000000000..30c70c40dd --- /dev/null +++ b/files/ca/web/javascript/reference/errors/nomes-lectura/index.html @@ -0,0 +1,78 @@ +--- +title: 'TipusError: "x" es només de lectura' +slug: Web/JavaScript/Reference/Errors/Nomes-Lectura +tags: + - Errors + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/Read-only +--- +
{{jsSidebar("Errors")}}
+ +

Missatge

+ +
TipusError: "x" es només de lectura (Firefox)
+TipusError: 0 es només de lectura (Firefox)
+TipusError: No es pot fer l'assignació a la propietat 'x' de #<Object> que es només de lectura (Chrome)
+TipusError: No es pot fer l'assignació a la propietat '0' de [object Array] (Chrome)
+
+ +

Tipus d'error

+ +

{{jsxref("TypeError")}}

+ +

Qué ha anat malament?

+ +

La variable global o propietat de l'objecte a la qual s'ha volgut fer l'assignació es només de lectura. (Tècnicament, es una propietat de no-escriptura.)

+ +

Aquest error succeeix només en codi en mode estricte. En codi en mode no estricte, l'assignació es ignorada de manera silenciosa.

+ +

Exemples

+ +

Casos invàlids

+ +

Propietats de només lectura no son súper comuns, però es poden donar quan es fa servir {{jsxref("Object.defineProperty()")}} o {{jsxref("Object.freeze()")}}.

+ +
'use strict';
+var obj = Object.freeze({name: 'Elsa', score: 157});
+obj.score = 0;  // TypeError
+
+'use strict';
+Object.defineProperty(this, 'LUNG_COUNT', {value: 2, writable: false});
+LUNG_COUNT = 3;  // TypeError
+
+'use strict';
+var frozenArray = Object.freeze([0, 1, 2]);
+frozenArray[0]++;  // TypeError
+
+ +

També hi ha unes poques propietats de només lectura en la construcció de JavaScript. Potser que hagis provat de redefinir una constant matemàtica.

+ +
'use strict';
+Math.PI = 4;  // TypeError
+ +

Ho sentim, no pots fer això.

+ +

La variable global undefined també es només de lectura, llavors no pots silenciar l'infame error "undefined no es una funció" fent això:

+ +
'use strict';
+undefined = function() {};  // TypeError: "undefined" es només de lectura
+
+ +

Valid cases

+ +
'use strict';
+var obj = Object.freeze({name: 'Score', points: 157});
+obj = {name: obj.name, points: 0};   // reemplaçant-ho amb un nou objecte funciona
+
+'use strict';
+var LUNG_COUNT = 2;  // Una `var` funciona, perque no es de només lectura
+LUNG_COUNT = 3;  // ok (anatòmicament potser, però poc probable)
+
+ +

See also

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