From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../reference/global_objects/object/is/index.html | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 files/it/web/javascript/reference/global_objects/object/is/index.html (limited to 'files/it/web/javascript/reference/global_objects/object/is') diff --git a/files/it/web/javascript/reference/global_objects/object/is/index.html b/files/it/web/javascript/reference/global_objects/object/is/index.html new file mode 100644 index 0000000000..ffb979fcb5 --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/object/is/index.html @@ -0,0 +1,130 @@ +--- +title: Object.is() +slug: Web/JavaScript/Reference/Global_Objects/Object/is +tags: + - Comparazione + - Condizionale + - Condizione + - ECMAScript 2015 + - Equalità + - Italiano + - JavaScript + - Oggetto + - Uguaglianza + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Object/is +--- +
{{JSRef}}
+ +

Il metodo Object.is() determina se i due parametri di input hanno lo stesso valore.

+ +

Sintassi

+ +
Object.is(value1, value2);
+ +

Parametri

+ +
+
value1
+
Il primo valore da comparare.
+
value2
+
Il secondo valore da comparare.
+
+ +

Return value

+ +

A {{jsxref("Boolean")}} indicating whether or not the two arguments are the same value.

+ +

Descrizione

+ +

Object.is() determina se due valori sono uguali. Due valori sono uguali se sono :

+ + + +

Questo non è la stessa uguaglianza dell'operatore {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}. L'operatore {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}} applica varie conversioni ad entrambi (se non sono dello stesso tipo) prima di testare l'uguaglianza (ad esempio, "" == false risultando true), ma Object.is non converte i loro valori.

+ +

Inoltre questo non è la stessa uguaglianza dell'operatore {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}. L'operatore {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}} (ed anche l'operatore {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}) trattano i numeri -0 e +0 come uguali e trattano {{jsxref("Number.NaN")}} differentemente da {{jsxref("NaN")}}.

+ +

Esempi

+ +
Object.is('foo', 'foo');     // true
+Object.is(window, window);   // true
+
+Object.is('foo', 'bar');     // false
+Object.is([], []);           // false
+
+var test = { a: 1 };
+Object.is(test, test);       // true
+
+Object.is(null, null);       // true
+
+// Casi speciali
+Object.is(0, -0);            // false
+Object.is(-0, -0);           // true
+Object.is(NaN, 0/0);         // true
+
+ +

Polyfill

+ +
if (!Object.is) {
+  Object.is = function(x, y) {
+    // Algoritmo SameValue
+    if (x === y) { // Steps 1-5, 7-10
+      // Steps 6.b-6.e: +0 != -0
+      return x !== 0 || 1 / x === 1 / y;
+    } else {
+     // Step 6.a: NaN == NaN
+     return x !== x && y !== y;
+    }
+  };
+}
+ +

Specifiche

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#sec-object.is', 'Object.is')}}{{Spec2('ES2015')}}Definizione iniziale.
{{SpecName('ESDraft', '#sec-object.is', 'Object.is')}}{{Spec2('ESDraft')}} 
+ +

Compatibilità coi browser

+ +
+ + +

{{Compat("javascript.builtins.Object.is")}}

+
+ +

Vedi anche

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