From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../global_objects/object/assign/index.html | 268 --------------------- .../global_objects/object/constructor/index.html | 222 ----------------- .../global_objects/object/create/index.html | 234 ------------------ .../object/defineproperties/index.html | 224 ----------------- .../global_objects/object/freeze/index.html | 210 ---------------- .../object/getprototypeof/index.html | 130 ---------- .../object/hasownproperty/index.html | 164 ------------- .../reference/global_objects/object/index.html | 224 ----------------- .../reference/global_objects/object/is/index.html | 130 ---------- .../global_objects/object/isfrozen/index.html | 184 -------------- .../global_objects/object/issealed/index.html | 146 ----------- .../global_objects/object/keys/index.html | 167 ------------- .../global_objects/object/seal/index.html | 157 ------------ .../global_objects/object/tostring/index.html | 170 ------------- 14 files changed, 2630 deletions(-) delete mode 100644 files/it/web/javascript/reference/global_objects/object/assign/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/constructor/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/create/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/defineproperties/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/freeze/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/getprototypeof/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/hasownproperty/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/is/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/isfrozen/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/issealed/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/keys/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/seal/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/object/tostring/index.html (limited to 'files/it/web/javascript/reference/global_objects/object') diff --git a/files/it/web/javascript/reference/global_objects/object/assign/index.html b/files/it/web/javascript/reference/global_objects/object/assign/index.html deleted file mode 100644 index 6280745df2..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/assign/index.html +++ /dev/null @@ -1,268 +0,0 @@ ---- -title: Object.assign() -slug: Web/JavaScript/Reference/Global_Objects/Object/assign -translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign ---- -
{{JSRef}}
- -

Sommario

- -

La funzione Object.assign() copia tutte le proprietà enumerabili da uno o più oggetti di origine in un oggetto di destinazione. Restituisce l'oggetto di destinazione.

- -

Sintassi

- -
Object.assign(target, ...sources)
- -

Parametri

- -
-
target
-
L'oggetto di destinazione.
-
sources
-
Gli oggetti di origine.
-
- -

Descrizione

- -

La funzione Object.assign() copia soltanto le proprietà enumerabili appartenenti agli oggetti di origine (non quelle che fanno parte della loro catena dei prototipi) in un oggetto di destinazione. Utilizza [[Get]] sugli oggetti di origine e [[Put]] su quello di destinazione, quindi invoca getter e setter, quando presenti. Quindi assegna le proprietà, piuttosto che limitarsi a copiarle o a definirne di nuove. Ciò lo rende inadatto per aggiungere nuove proprietà in un prototipo se le proprietà vengono copiate da un oggetto contenente getter o setter. Per copiare le proprietà, incluso il fatto di essere enumerabili o no, in un prototipo, bisognerebbe usare {{jsxref("Object.defineProperty()")}}.

- -

Vengono copiate sia le proprietà aventi come nomi delle {{jsxref("String", "stringhe")}} che dei {{jsxref("Symbol", "simboli")}}.

- -

In caso di errore, per esempio se una proprietà non è sovrascrivibile, viene generato un {{jsxref("TypeError")}}, e l'oggetto di destinazione rimane invariato.

- -

Notare che Object.assign() non genera un errore se uno dei valori di origine è {{jsxref("null")}} o {{jsxref("undefined")}}.

- -

Esempi

- -

Clonare un oggetto

- -

Si potrebbe pensare di clonare un oggetto semplicemente assegnandolo ad un altra variabile:

- -
var obj = { a: 1 };
-var copia = obj;
-console.log(obj, copia); // { a: 1 }, { a: 1 }
-obj.a = 2;
-console.log(obj, copia); // { a: 2 }, { a: 2 }
-                         // Ma copia.a non valeva 1?
- -

Utilizzando Object.assign() il problema non si verifica:

- -
var obj = { a: 1 };
-var copia = Object.assign({}, obj);
-console.log(obj, copia); // { a: 1 }, { a: 1 }
-obj.a = 2;
-console.log(obj, copia); // { a: 2 }, { a: 1 }
-
- -

Unire più oggetti

- -
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 }, le proprietà vengono aggiunte all'oggetto di destinazione
-
- -

Copiare proprietà aventi come indici dei simboli

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

Le proprietà ereditate o non-enumerabili non vengono copiate

- -
var obj = Object.create({ foo: 1 }, { // foo è una proprietà ereditata
-  bar: {
-    value: 2  // bar è una proprietà non-enumerabile
-  },
-  baz: {
-    value: 3,
-    enumerable: true  // baz è una proprietà enumerabile
-  }
-});
-
-var copia = Object.assign({}, obj);
-console.log(copia); // { baz: 3 }
-
- -

I valori primitivi vengono trasformati in oggetti

- -
var v1 = '123';
-var v2 = true;
-var v3 = 10;
-var v4 = Symbol("foo");
-
-var obj = Object.assign({}, v1, null, v2, undefined, v3, v4);
-// I valori primitivi vengono trasformati in oggetti, null e undefined ignorati.
-// Notare che solo le stringhe hanno proprietà enumerabili
-console.log(obj); // { "0": "1", "1": "2", "2": "3" }
-
- -

Se viene generata un eccezione, la funzione si ferma

- -
var destinazione = Object.defineProperty({}, 'foo', {
-  value: 1,
-  writeable: false
-}); // destinazione.foo non può essere modificata
-
-Object.assign(destinazione, { bar: 2 }, { foo2: 3, foo: 3, foo3: 3 }, { baz: 4 });
-// TypeError: "foo" is read-only
-// L'eccezione viene generata quando si modifica destinazione.foo
-
-console.log(destinazione.bar);  // 2, Il primo oggetto viene copiato correttamente
-console.log(destinazione.foo2); // 3, La prima proprietà del secondo oggetto viene copiata correttamente
-console.log(destinazione.foo);  // 1, L'eccezione viene generata qui
-console.log(destinazione.foo3); // undefined, la funzione ha già finto di copiare
-console.log(destinazione.baz);  // undefined, la funzione ha già finto di copiare
-
- -

Copiare i getter

- -
var obj = {
-  foo: 1,
-  get bar() {
-    return 2;
-  }
-};
-
-var copia = Object.assign({}, obj);
-console.log(copia);
-// { foo: 1, bar: 2 }, non viene copiato il getter obj.bar, ma il suo valore
-
-// Questa funzione copia mantenendo getter e setter
-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 copia = myAssign({}, obj);
-console.log(copia);
-// { foo:1, get bar() { return 2 } }
-
- -

Polyfill

- -

Questo polyfill non supporta i simboli (che comunque non sono supportati da ECMAScript 5):

- -
if (!Object.assign) {
-  Object.defineProperty(Object, 'assign', {
-    enumerable: false,
-    configurable: true,
-    writable: true,
-    value: function(target, firstSource) {
-      '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;
-    }
-  });
-}
-
- -

Specifiche

- - - - - - - - - - - - - - -
SpecificaStatoCommenti
{{SpecName('ES2015', '#sec-object.assign', 'Object.assign')}}{{Spec2('ES2015')}}Definizione iniziale.
- -

Compatibilità con i browser

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - - - -
FunzionalitàChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Supporto di base{{CompatChrome("45")}}{{CompatVersionUnknown}}{{CompatGeckoDesktop("34")}}{{CompatNo}}{{CompatOpera("32")}}{{CompatSafari("9")}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
FunzionalitàAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Supporto di base{{CompatNo}}{{CompatChrome("45")}}{{CompatVersionUnknown}}{{CompatGeckoMobile("34")}}{{CompatNo}}{{CompatNo}}{{CompatVersionUnknown}}
-
- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/constructor/index.html b/files/it/web/javascript/reference/global_objects/object/constructor/index.html deleted file mode 100644 index 6a9c339acb..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/constructor/index.html +++ /dev/null @@ -1,222 +0,0 @@ ---- -title: Object.prototype.constructor -slug: Web/JavaScript/Reference/Global_Objects/Object/constructor -translation_of: Web/JavaScript/Reference/Global_Objects/Object/constructor ---- -
{{JSRef}}
- -

La proprietà constuctor restituisce un riferimento alla funzione del costruttore {{jsxref ("Object")}} che ha creato l'oggetto istanza. Notare che il valore di questa proprietà è un riferimento alla funzione stessa, non una stringa contenente il nome della funzione.Il valore è di sola lettura solo per i valori primitivi come 1, true e "test".

- -

-
-
-
-

Description

- -
Tutti gli oggetti (ad eccezione degli object.create (null)) avranno una proprietà constuctor. Gli oggetti creati senza l'uso esplicito di una funzione di constructor (come oggetti letterali e array-letterali) avranno una proprietà constructor che punta al tipo di costrunctor dell'oggetto fondamentale per quell'oggetto.
- -
let o = {}
-o.constructor === Object // true
-
-let o = new Object
-o.constructor === Object // true
-
-let a = []
-a.constructor === Array // true
-
-let a = new Array
-a.constructor === Array // true
-
-let n = new Number(3)
-n.constructor === Number // true
-
- -

Examples

- -

Displaying the constructor of an object

- -

The following example creates a constructor (Tree) and an object of that type (theTree). The example then displays the constructor property for the object theTree.

- -
function Tree(name) {
-  this.name = name
-}
-
-let theTree = new Tree('Redwood')
-console.log('theTree.constructor is ' + theTree.constructor)
-
- -

This example displays the following output:

- -
theTree.constructor is function Tree(name) {
-  this.name = name
-}
-
- -

Changing the constructor of an object

- -

One can assign the constructor property for any value except null and undefined since those don't have a corresponding constructor function (like String, Number, Boolean etc.), but values which are primitives won't keep the change (with no exception thrown). This is due to the same mechanism, which allows one to set any property on primitive values (except null and undefined) with no effect. namely wherenever one uses such a primitive as an object an instance of the corresponding constructor is created and discarded right after the statement was executed.

- -
let val = null;
-val.constructor = 1; //TypeError: var is null
-
-val = 'abc';
-val.constructor = Number; //val.constructor === String
-
-val.foo = 'bar'; //An implicit instance of String('abc') was created and assigned the prop foo
-val.foo === undefined; //true, since a new instance of String('abc') was created for this comparison, which doesn't have the foo property
- -

So basically one can change the value of the constructor property for anything, except the primitives mentioned above, note that changing the constructor property does not affect the instanceof operator:

- -
let a = [];
-a.constructor = String
-a.constructor === String // true
-a instanceof String //false
-a instanceof Array //true
-
-a = new Foo();
-a.constructor = 'bar'
-a.constructor === 'bar' // true
-
-//etc.
- -

If the object is sealed/frozen then the change has no effect and no exception is thrown:

- -
let a = Object.seal({});
-a.constructor = Number;
-a.constructor === Object; //true
- -

Changing the constructor of a function

- -

Mostly this property is used for defining a function as a function-constructor with further calling it with new and prototype-inherits chain.

- -
function Parent() { /* ... */ }
-Parent.prototype.parentMethod = function parentMethod() {}
-
-function Child() {
-   Parent.call(this) // Make sure everything is initialized properly
-}
-Child.prototype = Object.create(Parent.prototype) // re-define child prototype to Parent prototype
-
-Child.prototype.constructor = Child // return original constructor to Child
- -

But when do we need to perform the last line here? Unfortunately, the answer is: it depends.

- -

Let's try to define the cases in which re-assignment of the original constructor will play a major role, and when it will be one superfluous line of code.

- -

Take the following case: the object has the create() method to create itself.

- -
function Parent() { /* ... */ }
-function CreatedConstructor() {
-   Parent.call(this)
-}
-
-CreatedConstructor.prototype = Object.create(Parent.prototype)
-
-CreatedConstructor.prototype.create = function create() {
-  return new this.constructor()
-}
-
-new CreatedConstructor().create().create() // TypeError undefined is not a function since constructor === Parent
- -

In the example above the exception will be shown since the constructor links to Parent.

- -

To avoid this, just assign the necessary constructor you are going to use.

- -
function Parent() { /* ... */ }
-function CreatedConstructor() { /* ... */ }
-
-CreatedConstructor.prototype = Object.create(Parent.prototype)
-CreatedConstructor.prototype.constructor = CreatedConstructor // sets the correct constructor for future use
-
-CreatedConstructor.prototype.create = function create() {
-  return new this.constructor()
-}
-
-new CreatedConstructor().create().create() // it's pretty fine
- -

Ok, now it's pretty clear why changing the constructor can be useful.

- -

Let's consider one more case.

- -
function ParentWithStatic() {}
-
-ParentWithStatic.startPosition = { x: 0, y:0 } // Static member property
-ParentWithStatic.getStartPosition = function getStartPosition() {
-  return this.startPosition
-}
-
-function Child(x, y) {
-  this.position = {
-    x: x,
-    y: y
-  }
-}
-
-Child = Object.assign(ParentWithStatic)
-Child.prototype = Object.create(ParentWithStatic.prototype)
-Child.prototype.constructor = Child
-
-Child.prototype.getOffsetByInitialPosition = function getOffsetByInitialPosition() {
-  let position = this.position
-  let startPosition = this.constructor.getStartPosition() // error undefined is not a function, since the constructor is Child
-
-  return {
-    offsetX: startPosition.x - position.x,
-    offsetY: startPosition.y - position.y
-  }
-};
- -

For this example we need either to stay parent constructor to continue to work properly or reassign static properties to child's constructor:

- -
...
-Child = Object.assign(ParentWithStatic) // Notice that we assign it before we create(...) a prototype below
-Child.prototype = Object.create(ParentWithStatic.prototype)
-...
-
- -

or assign parent constructor identifier to a separate property on the Child constructor function and access it via that property:

- -
...
-Child.parentConstructor = ParentWithStatic
-Child.prototype = Object.create(ParentWithStatic.prototype)
-...
-   let startPosition = this.constructor.parentConstructor.getStartPosition()
-...
-
- -
-

Summary: Manually updating or setting the constructor can lead to differrent and sometimes confusing consequences. To prevent this, just define the role of constructor in each specific case. In most cases, constructor is not used and reassignment of it is not necessary.

-
- -

Specifications

- - - - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-object.prototype.constructor', 'Object.prototype.constructor')}}
- -

Browser compatibility

- - - -

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

- -

See also

- - - - diff --git a/files/it/web/javascript/reference/global_objects/object/create/index.html b/files/it/web/javascript/reference/global_objects/object/create/index.html deleted file mode 100644 index d2b020b955..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/create/index.html +++ /dev/null @@ -1,234 +0,0 @@ ---- -title: Object.create() -slug: Web/JavaScript/Reference/Global_Objects/Object/create -tags: - - Creazione - - Oggetto - - Prototipo - - metodo -translation_of: Web/JavaScript/Reference/Global_Objects/Object/create ---- -
- {{JSRef("Global_Objects", "Object")}}
-

Sommario

-

Il metodo Object.create() crea un nuovo oggetto a partire dall'oggetto prototipo e dalle proprietà specificati.

-

Sintassi

-
Object.create(proto[, propertiesObject])
-

Parametri

-
-
- proto
-
- L'oggetto che farà da prototipo per il nuovo oggetto creato.
-
- propertiesObject
-
- Opzionale. Se specificato e non {{jsxref("Global_Objects/undefined", "undefined")}}, un oggetto le cui proprie proprietà enumerabili (ovvero, quelle proprietà definite esclusivamente su di sé e non quelle enumerabili presenti nella sua catena dei prototipi) specificano descrittori di proprietà da aggiungere all'oggetto appena creato, con i corrispondenti nomi di proprietà. Queste proprietà corrispondono al secondo argomento di {{jsxref("Object.defineProperties()")}}.
-
-

Throws

-

Lancia un'eccezione di tipo {{jsxref("Global_Objects/TypeError", "TypeError")}} se il parametro  proto non è {{jsxref("Global_Objects/null", "null")}} oppure un oggetto.

-

Esempi

-

Esempio: ereditarietà classica con Object.create

-

Sotto, trovi un esempio di come implementare un'ereditarietà classica usando Object.create. Si tratta di un'ereditarietà singola, l'unica supportata da Javascript.

-
// Shape - superclass
-function Shape() {
-  this.x = 0;
-  this.y = 0;
-}
-
-// superclass method
-Shape.prototype.move = function(x, y) {
-  this.x += x;
-  this.y += y;
-  console.info('Shape moved.');
-};
-
-// Rectangle - subclass
-function Rectangle() {
-  Shape.call(this); // call super constructor.
-}
-
-// subclass extends superclass
-Rectangle.prototype = Object.create(Shape.prototype);
-Rectangle.prototype.constructor = Rectangle;
-
-var rect = new Rectangle();
-
-console.log("Is rect an instance of Rectangle? " + (rect instanceof Rectangle)); // true
-console.log("Is rect an instance of Shape? " + (rect instanceof Shape)); // true
-
-rect.move(1, 1); // Outputs, 'Shape moved.'
-
-

Se desideri ereditare proprietà e metodi da oggetti multipli, puoi utilizzare dei mixins.

-
function MyClass() {
-  SuperClass.call(this);
-  OtherSuperClass.call(this);
-}
-
-MyClass.prototype = Object.create(SuperClass.prototype); // inherit
-mixin(MyClass.prototype, OtherSuperClass.prototype); // mixin
-
-MyClass.prototype.myMethod = function() {
-  // do a thing
-};
-
-

La funzione mixin copia le funzioni dell'oggetto prototype della superclasse nell'oggetto prototype della sottoclasse; la funzione mixin deve essere implementata dall'utente. Un esempio di funzione simil mixin potrebbe essere jQuery.extend.

-

Esempio: Usare l'argomento propertiesObject con Object.create

-
var o;
-
-// create an object with null as prototype
-o = Object.create(null);
-
-
-o = {};
-// is equivalent to:
-o = Object.create(Object.prototype);
-
-
-// Example where we create an object with a couple of sample properties.
-// (Note that the second parameter maps keys to *property descriptors*.)
-o = Object.create(Object.prototype, {
-  // foo is a regular 'value property'
-  foo: { writable: true, configurable: true, value: 'hello' },
-  // bar is a getter-and-setter (accessor) property
-  bar: {
-    configurable: false,
-    get: function() { return 10; },
-    set: function(value) { console.log('Setting `o.bar` to', value); }
-  }
-});
-
-
-function Constructor() {}
-o = new Constructor();
-// is equivalent to:
-o = Object.create(Constructor.prototype);
-// Of course, if there is actual initialization code in the
-// Constructor function, the Object.create cannot reflect it
-
-
-// create a new object whose prototype is a new, empty object
-// and a adding single property 'p', with value 42
-o = Object.create({}, { p: { value: 42 } });
-
-// by default properties ARE NOT writable, enumerable or configurable:
-o.p = 24;
-o.p;
-// 42
-
-o.q = 12;
-for (var prop in o) {
-  console.log(prop);
-}
-// 'q'
-
-delete o.p;
-// false
-
-// to specify an ES3 property
-o2 = Object.create({}, {
-  p: {
-    value: 42,
-    writable: true,
-    enumerable: true,
-    configurable: true
-  }
-});
-
-

Polyfill

-

Questo polyfill implementa il caso di utilizzo principale, ovvero creare un nuovo oggetto specificando un oggetto prototipo, ma non prende in considerazione il secondo argomento dell'API orginale.

-
if (typeof Object.create != 'function') {
-  Object.create = (function() {
-    var Object = function() {};
-    return function (prototype) {
-      if (arguments.length > 1) {
-        throw Error('Second argument not supported');
-      }
-      if (typeof prototype != 'object') {
-        throw TypeError('Argument must be an object');
-      }
-      Object.prototype = prototype;
-      var result = new Object();
-      Object.prototype = null;
-      return result;
-    };
-  })();
-}
-
-

Specifiche

- - - - - - - - - - - - - - - - - - -
SpecificaStatoCommento
{{SpecName('ES5.1', '#sec-15.2.3.5', 'Object.create')}}{{Spec2('ES5.1')}}Definizione iniziale. Implementato in JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.create', 'Object.create')}}{{Spec2('ES6')}} 
-

Compatibilità browser

-
- {{CompatibilityTable}}
-
- - - - - - - - - - - - - - - - - - - -
CaratteristicaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Supporto base{{CompatChrome("5")}}{{CompatGeckoDesktop("2")}}{{CompatIE("9")}}{{CompatOpera("11.60")}}{{CompatSafari("5")}}
-
-
- - - - - - - - - - - - - - - - - - - - - -
CaratteristicaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Supporto base{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoDesktop("2")}}{{CompatVersionUnknown}}{{CompatOperaMobile("11.50")}}{{CompatVersionUnknown}}
-
-

Basato sulla tabella di compatibilità di Kangax.

-

Vedi anche

- diff --git a/files/it/web/javascript/reference/global_objects/object/defineproperties/index.html b/files/it/web/javascript/reference/global_objects/object/defineproperties/index.html deleted file mode 100644 index c905420eb2..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/defineproperties/index.html +++ /dev/null @@ -1,224 +0,0 @@ ---- -title: Object.defineProperties() -slug: Web/JavaScript/Reference/Global_Objects/Object/defineProperties -translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperties ---- -
{{JSRef}}
- -

Il metodo Object.defineProperties() definisce nuove proprietà o modifica le proprietà esistenti, direttamente sull'oggetto di ritorno.

- -

Sintassi

- -
Object.defineProperties(obj, props)
- -

Parametri

- -
-
obj
-
L'oggetto su cui definire le nuove proprietà o modificare le esistenti proprietà.
-
props
-
Un oggetto che contiene le proprietà enumerabili. Per ogni proprietà troviamo dei descrittori della proprietà stessa, che ne impostano il comportamento. Suddividiamo i descrittori in due tipologie: il data descriptors e i descrittorei che ne regolano gli accessi (guarda {{jsxref("Object.defineProperty()")}} per maggiori dettagli). I descrittori hanno le seguenti c:
-
-
-
configurable
-
true se e solo se la proprietà individuata dal descrittore può essere cambiata e se la proprietà può essere cancellata dal presente oggetto.
- Defaults a false.
-
enumerable
-
true se e solo se la proprietà è visualizzabile durante una enumerazione delle proprietà del presente oggetto (es. for-in)
- Defaults a false.
-
- -
-
value
-
Il valore associato con la proprietà che si sta definendo. Può essere un qualsiasi valore valido di Javascript (number, object, function, ecc...)
- Defaults a {{jsxref("undefined")}}.
-
writable
-
true se e solo se il valore associato per la proprietà può essere cambiato con un {{jsxref("Operators/Assignment_Operators", "operatore di assegnazione", "", 1)}}.
- Defaults to false.
-
- -
-
get
-
Una funzione che serve da getter (prelevare il dato) per la proprietà, o {{jsxref("undefined")}} se non è presente un getter. Il valore di ritorno della funzione verrà usato come valore della proprietà
- Defaults a {{jsxref("undefined")}}.
-
set
-
Una funzione che serve da setter (impostare il dato) per la proprietà {{jsxref("undefined")}} se non è presente il setter. La funzione riceverà un solo argomento che verrà assegnato come valore della proprietà.
- Defaults a {{jsxref("undefined")}}.
-
-
-
- -

Valore di ritorno

- -

L'oggetto che è stato passato alla funzione.

- -

Descrizione

- -

Object.defineProperties, in sostanza, definisce tutte le proprietà di un oggetto, corrispondenti alle proprietà "own" proprie di un oggetto obj.

- -

Esempio

- -
var obj = {};
-Object.defineProperties(obj, {
-  'property1': {
-    value: true,
-    writable: true
-  },
-  'property2': {
-    value: 'Hello',
-    writable: false
-  }
-  // etc. etc.
-});
-
- -

Polyfill

- -

Assumendo di eseguire un ambiente precedente con tutti i nomi e le proprietà che fanno riferimento ai valori iniziali, Object.defineProperties è quasi completamente equivalente (nota il commento in isCallable) al seguente reimplementazione in Javascript:

- -
function defineProperties(obj, properties) {
-  function convertToDescriptor(desc) {
-    function hasProperty(obj, prop) {
-      return Object.prototype.hasOwnProperty.call(obj, prop);
-    }
-
-    function isCallable(v) {
-      // NB: modify as necessary if other values than functions are callable.
-      return typeof v === 'function';
-    }
-
-    if (typeof desc !== 'object' || desc === null)
-      throw new TypeError('bad desc');
-
-    var d = {};
-
-    if (hasProperty(desc, 'enumerable'))
-      d.enumerable = !!desc.enumerable;
-    if (hasProperty(desc, 'configurable'))
-      d.configurable = !!desc.configurable;
-    if (hasProperty(desc, 'value'))
-      d.value = desc.value;
-    if (hasProperty(desc, 'writable'))
-      d.writable = !!desc.writable;
-    if (hasProperty(desc, 'get')) {
-      var g = desc.get;
-
-      if (!isCallable(g) && typeof g !== 'undefined')
-        throw new TypeError('bad get');
-      d.get = g;
-    }
-    if (hasProperty(desc, 'set')) {
-      var s = desc.set;
-      if (!isCallable(s) && typeof s !== 'undefined')
-        throw new TypeError('bad set');
-      d.set = s;
-    }
-
-    if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d))
-      throw new TypeError('identity-confused descriptor');
-
-    return d;
-  }
-
-  if (typeof obj !== 'object' || obj === null)
-    throw new TypeError('bad obj');
-
-  properties = Object(properties);
-
-  var keys = Object.keys(properties);
-  var descs = [];
-
-  for (var i = 0; i < keys.length; i++)
-    descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
-
-  for (var i = 0; i < descs.length; i++)
-    Object.defineProperty(obj, descs[i][0], descs[i][1]);
-
-  return obj;
-}
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES5.1', '#sec-15.2.3.7', 'Object.defineProperties')}}{{Spec2('ES5.1')}}Initial definition. Implemented in JavaScript 1.8.5
{{SpecName('ES6', '#sec-object.defineproperties', 'Object.defineProperties')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-object.defineproperties', 'Object.defineProperties')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FeatureFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Basic support{{CompatGeckoDesktop("2")}}{{CompatChrome("5")}}{{CompatIE("9")}}{{CompatOpera("11.60")}}{{CompatSafari("5")}}
-
- -
- - - - - - - - - - - - - - - - - - - -
FeatureFirefox Mobile (Gecko)AndroidIE MobileOpera MobileSafari Mobile
Basic support{{CompatGeckoMobile("2")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatOperaMobile("11.5")}}{{CompatVersionUnknown}}
-
- -

See also

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

Il metodo Object.freeze() congela un oggetto: ne previene l'aggiunta, la modifica e la rimozione di proprietà, inclusa la loro enumerabilità, configurabilità e accessibilità. In sostanza, l'oggetto è reso effettivamente immutabile. Il metodo restituisce lo stesso oggetto che è stato passato alla funzione. 

- -

Sintassi

- -
Object.freeze(obj)
- -

Parametri

- -
-
obj
-
L'oggetto da congelare.
-
- -

Valore di ritorno

- -

L'oggetto passato alla funzione.

- -

Descrizione

- -

Nulla può essere aggiunto o rimosso dall'insieme delle proprietà di un oggetto congelato. Qualsiasi tentativo di fare ciò fallirebbe, o silenziosamente o attraverso il ritorno di un errore {{jsxref("TypeError")}} (più frequentemente, ma non necessariamente, quest'ultimo scenario accadrebbe in {{jsxref("Strict_mode", "strict mode", "", 1)}}).

- -

I valori delle proprietà non possono essere cambiati, anche quando si tratta di setters e getters. Da notare che se un oggetto costituisce il valore di una proprietà, esso può essere ancora modificato senza problemi, a meno che anch'esso non sia stato congelato.

- -

Esempi

- -
var obj = {
-  prop: function() {},
-  foo: 'bar'
-};
-
-// Nuove proprietà possono essere aggiunte, proprietà già esistenti possono
-// essere modificate o rimosse
-obj.foo = 'baz';
-obj.lumpy = 'woof';
-delete obj.prop;
-
-
-// Sia l'oggetto che viene passato che quello restituito verranno congelati.
-// No serve salvare l'oggetto restituito per congelare l'originale
-var o = Object.freeze(obj);
-
-o === obj; // true
-Object.isFrozen(obj); // === true
-
-// Adesso qualsiasi cambiamento fallirà
-obj.foo = 'quux'; // silenziosamente, non succede niente
-obj.quaxxor = 'the friendly duck'; // silenziosamente, non aggiungerà alcuna proprietò
-
-
-// ...e nella modalità strict questi tentativi di modifica faranno lanciare TypeErrors
-function fail(){
-  'use strict';
-  obj.foo = 'sparky'; // throws a TypeError
-  delete obj.quaxxor; // throws a TypeError
-  obj.sparky = 'arf'; // throws a TypeError
-}
-
-fail();
-
-
-// Tentare di cambiare attraverso Object.defineProperty farà anche lanciare un TypeError
-Object.defineProperty(obj, 'ohai', { value: 17 }); // throws a TypeError
-Object.defineProperty(obj, 'foo', { value: 'eit' }); // throws a TypeError
-
- -

Il seguente esempio mostra come oggetti che sono valori di proprietà possono essere mutati(il congelamento si ferma ad un solo livello di profondità).

- -
obj1 = {
-  internal: {}
-};
-
-Object.freeze(obj1);
-obj1.internal.a = 'aValue';
-
-obj1.internal.a // 'aValue'
-
-
-// Per fare un oggetto totalmente non modificabile, congela ciascun oggetto in obj.
-// Per farlo noi usiamo questa funzione.
-function deepFreeze(obj) {
-
-  // Prende tutti i nomi delle proprietà definite in obj
-  var propNames = Object.getOwnPropertyNames(obj);
-
-  // Congela tutte le proprietà prima di congelare obj
-  propNames.forEach(function(name) {
-    var prop = obj[name];
-
-    // Congela prop se esso è un oggetto
-    if (typeof prop == 'object' && prop !== null)
-      deepFreeze(prop);
-  });
-
-  // Congela se stesso (niente operazione se esso è già congelato)
-  return Object.freeze(obj);
-}
-
-obj2 = {
-  internal: {}
-};
-
-deepFreeze(obj2);
-obj2.internal.a = 'anotherValue';
-obj2.internal.a; // undefined
-
- -

Note

- -

In ES5, se l'argomento di questo metodo non è un oggetto, allora verrà ritornato un errore {{jsxref("TypeError")}}. In ES2015, un argomento che non è un oggetto verrà trattato come se fosse un normale oggetto già congelato, e verrà perciò semplicemente ritornato.

- -
> Object.freeze(1)
-TypeError: 1 is not an object // ES5 code
-
-> Object.freeze(1)
-1                             // ES2015 code
-
- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificaStatoCommento
{{SpecName('ES5.1', '#sec-15.2.3.9', 'Object.freeze')}}{{Spec2('ES5.1')}}Commento iniziale. Implementato in JavaScript 1.8.5.
{{SpecName('ES2015', '#sec-object.freeze', 'Object.freeze')}}{{Spec2('ES2015')}}
{{SpecName('ESDraft', '#sec-object.freeze', 'Object.freeze')}}{{Spec2('ESDraft')}}
- -

Compatibilità con i browser

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FunzionalitàFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Funzionalità di base{{CompatGeckoDesktop("2")}}{{CompatChrome("6")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5.1")}}
-
- -
- - - - - - - - - - - - - - - - - - - -
FunzionalitàFirefox Mobile (Gecko)AndroidIE MobileOpera MobileSafari Mobile
Funzionalità di base{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

Guarda anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/getprototypeof/index.html b/files/it/web/javascript/reference/global_objects/object/getprototypeof/index.html deleted file mode 100644 index dd72c6cdf3..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/getprototypeof/index.html +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: Object.getPrototypeOf() -slug: Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf -tags: - - ECMAScript5 - - ECMAScript6 - - JavaScript - - Method - - Object -translation_of: Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf ---- -
{{JSRef}}
- -

Il metodo Object.getPrototypeOf() restituisce il prototipo (ovvero il valore della proprietà interna [[Prototype]]) dell'oggetto specificato.

- -

Sintassi

- -
Object.getPrototypeOf(obj)
- -

Parametri

- -
-
obj
-
L'oggetto di cui si vuole ottenere il prototipo.
-
- -

Esempi

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

Note

- -

Se il parametro obj non è un oggetto, nello standard ES5 il metodo innescherà un'eccezione {{jsxref("TypeError")}}, mentre nello standard ES6 il parametro sarà assegnato forzatamente ad un {{jsxref("Object")}}.

- -
Object.getPrototypeOf("foo");
-// TypeError: "foo" is not an object (ES5 code)
-Object.getPrototypeOf("foo");
-// String.prototype                  (ES6 code)
-
- -

Specifiche

- - - - - - - - - - - - - - - - - - - -
SpecificaStatoCommenti
{{SpecName('ES5.1', '#sec-15.2.3.2', 'Object.getPrototypeOf')}}{{Spec2('ES5.1')}}Prima definizione.
{{SpecName('ES6', '#sec-object.getprototypeof', 'Object.getProtoypeOf')}}{{Spec2('ES6')}} 
- -

Compatibilità fra i Browser

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatChrome("5")}}{{CompatGeckoDesktop("1.9.1")}}{{CompatIE("9")}}{{CompatOpera("12.10")}}{{CompatSafari("5")}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

Note specifiche su Opera

- -

Anche se le vecchie versioni di Opera non supportano ancora il metodo Object.getPrototypeOf(), comunque dalla versione 10.50 è stata implementata la proprietà non standard {{jsxref("Object.proto", "__proto__")}}.

- -

Guarda anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/hasownproperty/index.html b/files/it/web/javascript/reference/global_objects/object/hasownproperty/index.html deleted file mode 100644 index 7287ed1e18..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/hasownproperty/index.html +++ /dev/null @@ -1,164 +0,0 @@ ---- -title: Object.prototype.hasOwnProperty() -slug: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty -tags: - - JavaScript - - Object - - Prototype - - hasOwnProperty - - metodo -translation_of: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty ---- -
{{JSRef}}
- -

Il metodo hasOwnProperty() restituisce un valore booleano che indica se l'oggetto ha la proprietà specificata come propria proprietà (invece di ereditarla).

- -
{{EmbedInteractiveExample("pages/js/object-prototype-hasownproperty.html")}}
- - - -

Sintassi

- -
obj.hasOwnProperty(prop)
- -

Parametri

- -
-
prop
-
Il nome della {{jsxref("String")}} o il {{Glossary("Symbol")}} della proprietà da testare.
-
- -

Valore di ritorno

- -

Un {{jsxref("Boolean")}} che indica se l'oggetto ha o meno la proprietà specificata come proprietà propria.

- -

Descrizione

- -

Tutti i discendenti di {{jsxref("Object")}} ereditano il metodo hasOwnProperty. Questo metodo può essere utilizzato per determinare se un oggetto ha la proprietà specificata come proprietà diretta di tale oggetto; a differenza dell'operatore {{jsxref("Operators/in", "in")}}, questo metodo non controlla una proprietà nella catena di prototipi dell'oggetto.

- -

Note

- -

hasOwnProperty restituisce true anche se il valore della proprietà è nullundefined.

- -
o = new Object();
-o.propOne = null;
-o.hasOwnProperty('propOne');   // ritorna true
-o.propTwo = undefined;
-o.hasOwnProperty('propTwo');   // ritorna true
-
- -

Esempi

- -

Usare hasOwnProperty per verificare l'esistenza di una proprietà

- -

L'esempio seguente determina se l'oggetto o contiene una proprietà denominata prop:

- -
o = new Object();
-o.hasOwnProperty('prop');   // ritorna false
-o.prop = 'exists';
-o.hasOwnProperty('prop');   // ritorna true
-
- -

Dirette vs. proprietà ereditate

- -

Il seguente esempio distingue tra proprietà dirette e proprietà ereditate attraverso la catena del prototipo:

- -
o = new Object();
-o.prop = 'exists';
-o.hasOwnProperty('prop');             // ritorna true
-o.hasOwnProperty('toString');         // ritorna false
-o.hasOwnProperty('hasOwnProperty');   // ritorna false
-
- -

Iterare sulle proprietà di un oggetto

- -

L'esempio seguente mostra come eseguire iterazioni sulle proprietà di un oggetto senza eseguire l'esecuzione su proprietà ereditate. Si noti che il ciclo {{jsxref("Statements/for...in", "for...in")}} sta già solo iterando gli oggetti enumerabili, quindi non si dovrebbe assumere in base alla mancanza di proprietà non enumerabili mostrate nel ciclo che hasOwnProperty è strettamente limitato agli elementi enumerabili (come con {{jsxref("Object.getOwnPropertyNames()")}}).

- -
var buz = {
-  fog: 'stack'
-};
-
-for (var name in buz) {
-  if (buz.hasOwnProperty(name)) {
-    console.log('this is fog (' +
-      name + ') for sure. Value: ' + buz[name]);
-  }
-  else {
-    console.log(name); // toString o qualcos'altro
-  }
-}
-
- -

Usare hasOwnProperty come nome di una proprietà

- -

JavaScript non protegge il nome della proprietà hasOwnProperty; quindi, se esiste la possibilità che un oggetto possa avere una proprietà con questo nome, è necessario utilizzare un hasOwnProperty esterno per ottenere risultati corretti:

- -
var foo = {
-  hasOwnProperty: function() {
-    return false;
-  },
-  bar: 'Here be dragons'
-};
-
-foo.hasOwnProperty('bar'); // restituisce sempre false
-
-// Usare hasOwnProperty di un altro oggetto
-// e chiamarlo con 'this' impostato su foo
-({}).hasOwnProperty.call(foo, 'bar'); // true
-
-// È anche possibile utilizzare la proprietà hasOwnProperty
-// dal prototipo Object per questo scopo
-Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
-
- -

Nota che nell'ultimo caso non ci sono oggetti appena creati.

- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificaStatoCommento
{{SpecName('ESDraft', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-15.2.4.5', 'Object.prototype.hasOwnProperty')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3')}}{{Spec2('ES3')}}Definizione iniziale Implementato in JavaScript 1.5.
- -

Compatibilità con i browser

- - - -

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

- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/index.html b/files/it/web/javascript/reference/global_objects/object/index.html deleted file mode 100644 index 8c567d9ea2..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/index.html +++ /dev/null @@ -1,224 +0,0 @@ ---- -title: Object -slug: Web/JavaScript/Reference/Global_Objects/Object -tags: - - Constructor - - JavaScript - - NeedsBrowserCompatibility - - NeedsMobileBrowserCompatibility - - Object - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/Object ---- -
{{JSRef("Global_Objects", "Object")}}
- -

Sommari

- -

Il costruttore Object crea un oggetto.

- -

Sintassi

- -
// Letterale
-{ [ coppiaNomeValore1 [, coppiaNomeValore2 [, ...coppiaNomeValoreN] ] ] }
-
-// Richiamato come una classe
-new Object( [ value ] )
- -

Parametri

- -
-
coppiaNomeValore1, coppiaNomeValore2, ... coppiaNomeValoreN
-
Coppie formate da un nome (una stringa) e un valore (di qualsiasi tipo), dove il nome è separato dal valore con i due punti.
-
-
{
-    "nome1": "valore1",
-    nome2: "valore2" // Gli apici nel nome sono opzionali
-};
-
-
-
- -
-
value
-
Qualsiasi valore.
-
- -

Descrizione

- -

Il costruttore Object crea un oggetto avente il valore dato. Se il valore è {{jsxref("Global_Objects/null", "null")}} o {{jsxref("Global_Objects/undefined", "undefined")}}, verrà creato un oggetto vuoto; altrimenti un oggetto del tipo corrispondente al valore dato. Se il valore è già un oggetto, verra restituito senza alcuna modifica.

- -

Quando richiamato come normale funzione, il comportamento di Object() è identico a new Object().

- -

Proprietà del costruttore Object

- -
-
Object.length
-
Ha valore pari a 1.
-
{{jsxref("Object.prototype")}}
-
Permette di aggiungere altre proprietà ad ogni oggetto di tipo Object.
-
- -

{{ jsOverrides("Function", "Properties", "prototype") }}

- -

Metodi del costruttore Object

- -
-
{{jsxref("Object.assign()")}} {{experimental_inline}}
-
Crea un nuovo oggetto copiando i valori di tutti le proprietà enumerabili da uno o più oggetti.
-
{{jsxref("Object.create()")}}
-
Crea un nuovo oggetto utilizzando il prototipo e le proprietà specificate.
-
{{jsxref("Object.defineProperty()")}}
-
Aggiunge una proprietà descritta dall'oggetto specificato.
-
{{jsxref("Object.defineProperties()")}}
-
Aggiunge più proprietà descritte dall'oggetto specificato.
-
{{jsxref("Object.freeze()")}}
-
Congela un oggetto: le sue proprietà non possono più essere cancellate o modificate.
-
{{jsxref("Object.getOwnPropertyDescriptor()")}}
-
Restituisce un oggetto che descriva la proprietà specificata.
-
{{jsxref("Object.getOwnPropertyNames()")}}
-
Restituisce un array contenente i nomi di tutte le proprietà (enumerabili e non-enumerabili) dell'oggetto specificato.
-
{{jsxref("Object.getPrototypeOf()")}}
-
Restituisce il prototipo dell'oggetto specificato.
-
{{jsxref("Object.is()")}} {{ experimental_inline() }}
-
Determina se due valori sono o no uguali (quindi lo stesso oggetto).
-
{{jsxref("Object.isExtensible()")}}
-
Determina se è permesso estendere un oggetto.
-
{{jsxref("Object.isFrozen()")}}
-
Determina se un oggetto è stato congelato.
-
{{jsxref("Object.isSealed()")}}
-
Determina se un oggetto è stato sigillato.
-
{{jsxref("Object.keys()")}}
-
Restituisce un array contenente i nomi di tutte le proprietà enumerabili dell'oggetto.
-
{{jsxref("Object.observe()")}} {{experimental_inline}}
-
Osserva i cambiamenti di un oggetto in modo asincrono.
-
{{jsxref("Object.preventExtensions()")}}
-
Impedisce ad un oggetto di essere esteso.
-
{{jsxref("Object.seal()")}}
-
Impedisce di eliminare le proprietà di un oggetto.
-
{{jsxref("Object.setPrototypeOf()")}} {{experimental_inline}}
-
-

Imposta i prototipo (quindi la proprietà intena ​[[Prototype]]) di un oggetto.

-
-
- -

{{jsOverrides("Function", "Methods", "create", "defineProperty", "defineProperties", "getOwnPropertyDescriptor", "getPrototypeOf")}}

- -

Instanze di Object e l'oggetto prototipo Object

- -

In JavaScript, tutti gli oggetti sono discendenti di Object; tutti gli oggetti ereditano metodi e proprietà di {{jsxref("Object.prototype")}}, anche se queste possono essere sovrascritte. Per esempio, i prototpipi degli altri costruttori sovrascrivono la proprietà constructor e forniscono un loro metodo toString(). I cambiamenti al prototipo di Object venogno estesi a tutti gli oggetti, eccetto quelli che sovrascrivono le proprietà e i metodi cambiati.

- -

Poprietà

- -

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

- -

Metodi

- -

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

- -

Esempi

- -

Usare Object con i valori null e undefined

- -

Questi esempi restituiscono tutti lo stesso oggetto:

- -
var o = {};
- -
var o = new Object();
-
- -
var o = new Object(undefined);
-
- -
var o = new Object(null);
-
- -

Usare Object per creare oggetti Boolean

- -

I seguenti esempi assegnano alla variabile o un oggetto {{jsxref("Global_Objects/Boolean", "Boolean")}}:

- -
var o = new Object(true);
-// Equivalente a new Boolean(true)
- -
var o = new Object(Boolean());
-// Equivalente a new Boolean(false)
- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificaStatoCommenti
ECMAScript 1st Edition. Implemented in JavaScript 1.0StandardDefinizione iniziale.
{{SpecName('ES5.1', '#sec-15.2', 'Object')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-object-objects', 'Object')}}{{Spec2('ES6')}} 
- -

Compatibilità con i browser

- -

{{ CompatibilityTable() }}

- -
- - - - - - - - - - - - - - - - - - - -
FunzionalitàChromeFirefox (Gecko)Internet ExplorerOperaSafari
Supporto di base{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FunzionalitàAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Supporto di base{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
-
- -

 

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 deleted file mode 100644 index ffb979fcb5..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/is/index.html +++ /dev/null @@ -1,130 +0,0 @@ ---- -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

- - diff --git a/files/it/web/javascript/reference/global_objects/object/isfrozen/index.html b/files/it/web/javascript/reference/global_objects/object/isfrozen/index.html deleted file mode 100644 index b1220f1ae5..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/isfrozen/index.html +++ /dev/null @@ -1,184 +0,0 @@ ---- -title: Object.isFrozen() -slug: Web/JavaScript/Reference/Global_Objects/Object/isFrozen -tags: - - ECMAScript 5 - - Function - - Italian - - Italiano - - JavaScript - - JavaScript 1.8.5 - - Method - - Object - - Oggetto - - funzione - - metodo -translation_of: Web/JavaScript/Reference/Global_Objects/Object/isFrozen ---- -
{{JSRef}}
- -

Il metodo Object.isFrozen() determina se un oggetto è {{jsxref("Object.freeze()", "congelato", "", 1)}}.

- -
{{EmbedInteractiveExample("pages/js/object-isfrozen.html")}}
- - - -

Syntax

- -
Object.isFrozen(obj)
- -

Parametri

- -
-
obj
-
L'oggetto da controllare.
-
- -

Valori di ritorno

- -

Un {{jsxref("Boolean")}} che indica se l'oggetto è congelato oppure no.

- -

Description

- -

Un oggetto è congelato solo e soltanto se non è {{jsxref("Object.isExtensible()", "estensibile", "", 1)}}, tutte le sue proprietà sono non-configurabili, e tutte le sue proprietà "data" (che non sono proprietà "accessor", quindi non hanno componenti getter o setters) non sono sovrascrivibili.

- -

Esempi

- -
// Un nuovo oggetto è estensibile, quindi non è congelato.
-Object.isFrozen({}); // === false
-
-// Un oggetto vuoto che non è estensibile
-// è vacuamente congelato.
-var vacuouslyFrozen = Object.preventExtensions({});
-Object.isFrozen(vacuouslyFrozen); // === true
-
-// Un nuovo oggetto con una sola proprietà è estensibile,
-// quindi non è congelato.
-var oneProp = { p: 42 };
-Object.isFrozen(oneProp); // === false
-
-// Prevenire le estensioni dell'oggetto, comunque non
-// lo rende congelato, perché la proprietà è comunque
-// configurabile(e sovrascrivibile).
-Object.preventExtensions(oneProp);
-Object.isFrozen(oneProp); // === false
-
-// ...ma poi cancellare quella proprietà, rende l'oggetto
-// vacuamente congelato.
-delete oneProp.p;
-Object.isFrozen(oneProp); // === true
-
-// Un oggetto non-estensibile con una proprietà non-sovrascrivibile,
-// ma comunque configurabile, non è congelato.
-var nonWritable = { e: 'plep' };
-Object.preventExtensions(nonWritable);
-Object.defineProperty(nonWritable, 'e', {
-  writable: false
-}); // rende non-sovrascrivibile
-Object.isFrozen(nonWritable); // === false
-
-// Cambiare quella proprietà in non-configurabile
-// rende l'oggetto congelato.
-Object.defineProperty(nonWritable, 'e', {
-  configurable: false
-}); // rende non-configurabile
-Object.isFrozen(nonWritable); // === true
-
-// Un oggetto non-estensibile con una proprietà non-configurabile
-// ma comunque sovrascribile, non è congelato.
-var nonConfigurable = { release: 'the kraken!' };
-Object.preventExtensions(nonConfigurable);
-Object.defineProperty(nonConfigurable, 'release', {
-  configurable: false
-});
-Object.isFrozen(nonConfigurable); // === false
-
-// Cambiare quella proprietà in non-sovrascribile,
-// allora rende l'oggetto congelato.
-Object.defineProperty(nonConfigurable, 'release', {
-  writable: false
-});
-Object.isFrozen(nonConfigurable); // === true
-
-// Un oggetto non-estensibile con una configurabile
-// proprietà "accessor", non è congelato.
-var accessor = { get food() { return 'yum'; } };
-Object.preventExtensions(accessor);
-Object.isFrozen(accessor); // === false
-
-// ...ma poi rendere quella proprietà non-configurabile
-// congela l'oggetto.
-Object.defineProperty(accessor, 'food', {
-  configurable: false
-});
-Object.isFrozen(accessor); // === true
-
-// Ma il metodo più veloce per congelare un oggetto,
-// è utilizzare il metodo Object.freeze su di esso.
-var frozen = { 1: 81 };
-Object.isFrozen(frozen); // === false
-Object.freeze(frozen);
-Object.isFrozen(frozen); // === true
-
-// Per definizione, un oggetto congelato non è estensibile.
-Object.isExtensible(frozen); // === false
-
-// E sempre per definizione, un oggetto congelato è anche sigillato.
-Object.isSealed(frozen); // === true
-
- -

Note

- -

In ES5, se l'argomento di questo metodo non è un'oggetto, allora verrà generato un {{jsxref("TypeError")}}. In ES2015, un argomento che non è un oggetto verrà trattato come se fosse un normale oggetto già congelato, e perciò verrà semplicemente ritornato true.

- -
Object.isFrozen(1);
-// TypeError: 1 non è un oggetto (codice in ES5)
-
-Object.isFrozen(1);
-// true                          (codice in ES2015)
-
- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES5.1', '#sec-15.2.3.12', 'Object.isFrozen')}}{{Spec2('ES5.1')}}Definizione iniziale. Implementato in JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.isfrozen', 'Object.isFrozen')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-object.isfrozen', 'Object.isFrozen')}}{{Spec2('ESDraft')}} 
- -

Compatibilità con i browser

- -
- - -

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

-
- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/issealed/index.html b/files/it/web/javascript/reference/global_objects/object/issealed/index.html deleted file mode 100644 index d3bdf1b76b..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/issealed/index.html +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Object.isSealed() -slug: Web/JavaScript/Reference/Global_Objects/Object/isSealed -tags: - - ECMAScript 5 - - Function - - Italian - - Italiano - - JavaScript - - JavaScript 1.8.5 - - Method - - Object - - Oggetto - - funzione - - metodo -translation_of: Web/JavaScript/Reference/Global_Objects/Object/isSealed ---- -
{{JSRef}}
- -

Il metodo Object.isSealed() determina se un oggetto è sigillato.

- -
{{EmbedInteractiveExample("pages/js/object-issealed.html")}}
- - - -

Syntax

- -
Object.isSealed(obj)
- -

Parametri

- -
-
obj
-
L'oggetto da controllare.
-
- -

Valore di ritorno

- -

Un {{jsxref("Boolean")}} che indica se l'oggetto è congelato oppure no.

- -

Descrizione

- -

Ritorna true se l'oggetto è sigillato, altrimenti false. Un oggetto  è sigillato se non è {{jsxref("Object.isExtensible", "estensibile", "", 1)}} e se tutte le sue proprietà sono non-configurabili e non possono essere rimosse (ma non necessariamente non-sovrascrivibili).

- -

Esempi

- -
// Gli oggetti non sono sigillati di default.
-var empty = {};
-Object.isSealed(empty); // === false
-
-// Se rendi un oggetto vuoto non-estensibile,
-// è vacuamente sigillato.
-Object.preventExtensions(empty);
-Object.isSealed(empty); // === true
-
-// Lo stesso non si verifica con un oggetto non vuoto,
-// a meno che le sue proprietà non sono tutte non-configurabili.
-var hasProp = { fee: 'fie foe fum' };
-Object.preventExtensions(hasProp);
-Object.isSealed(hasProp); // === false
-
-// Ma rendere tutte le sue proprietà non-configurabili
-// rende l'oggetto effettivamente sigillato.
-Object.defineProperty(hasProp, 'fee', {
-  configurable: false
-});
-Object.isSealed(hasProp); // === true
-
-// Il metodo più veloce per sigillare un oggetto, ovviamente,
-// è il metodo Object.seal.
-var sealed = {};
-Object.seal(sealed);
-Object.isSealed(sealed); // === true
-
-// Un oggetto sigillato è, per definizione, non-estensibile.
-Object.isExtensible(sealed); // === false
-
-// Un oggetto sigillato può anche essere congelato,
-// ma non è necessario.
-Object.isFrozen(sealed); // === true
-// (tutte le proprietà sono anche non-sovrascrivibili)
-
-var s2 = Object.seal({ p: 3 });
-Object.isFrozen(s2); // === false
-// ('p' è comunque sovrascrivibile)
-
-var s3 = Object.seal({ get p() { return 0; } });
-Object.isFrozen(s3); // === true
-// (per le proprietà "accessor", è importante solo la configurabilità della proprietà)
-
- -

Note

- -

In ES5, se l'argomento di questo metodo non è un'oggetto, allora verrà generato un {{jsxref("TypeError")}}. In ES2015, un argomento che non è un oggetto verrà trattato come se fosse un normale oggetto già sigillato, e perciò verrà semplicemente ritornato true.

- -
Object.isSealed(1);
-// TypeError: 1 non è un oggetto (codice in ES5)
-
-Object.isSealed(1);
-// true                          (codice in ES2015)
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES5.1', '#sec-15.2.3.11', 'Object.isSealed')}}{{Spec2('ES5.1')}}Definizione iniziale. Implementato in JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.issealed', 'Object.isSealed')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-object.issealed', 'Object.isSealed')}}{{Spec2('ESDraft')}} 
- -

Compatibilità con i browser

- -
- - -

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

-
- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/keys/index.html b/files/it/web/javascript/reference/global_objects/object/keys/index.html deleted file mode 100644 index ed748c0fad..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/keys/index.html +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: Object.keys() -slug: Web/JavaScript/Reference/Global_Objects/Object/keys -tags: - - ECMAScript5 - - JavaScript - - JavaScript 1.8.5 - - Metodi - - Oggetti -translation_of: Web/JavaScript/Reference/Global_Objects/Object/keys ---- -
- {{JSRef("Global_Objects", "Object")}}
-

Sommario

-

Il metodo Object.keys() restituisce un array contenente le proprietà enumerabili di un dato oggetto, nel medesimo ordine fornito da un ciclo for...in  (la differenza è che un ciclo for-in enumera anche le proprietà nella catena di prototipi).

-

Sintassi

-
Object.keys(obj)
-

Parametri

-
-
- obj
-
- L'oggetto del quale si devono restituire le proprietà enumerabili.
-
-

Descrizione

-

Object.keys restituisce un array i quali elementi sono stringhe corrispondenti alle proprietà enumerabili trovate direttamente in obj. L'ordine delle proprietà è lo stesso di quello dato ciclando manualmente sulle proprietà dell'oggetto.

-

Esempi

-
var arr = ["a", "b", "c"];
-alert(Object.keys(arr)); // chiama alert con argomento "0,1,2"
-
-// array like object
-var obj = { 0 : "a", 1 : "b", 2 : "c"};
-alert(Object.keys(obj)); // chiama alert con argomento "0,1,2"
-
-// array like object with random key ordering
-var an_obj = { 100: "a", 2: "b", 7: "c"};
-alert(Object.keys(an_obj)); // chiama alert con argomento "2, 7, 100"
-
-// getFoo is property which isn't enumerable
-var my_obj = Object.create({}, { getFoo : { value : function () { return this.foo } } });
-my_obj.foo = 1;
-
-alert(Object.keys(my_obj)); // chiama alert con foo come unico argomento
-
-

Per ottenere tutte le proprietà, anche quelle non enumerabili, si veda {{jsxref("Object.getOwnPropertyNames")}}.

-

Polyfill

-

Per aggiungere un supporto equivalente a Object.keys, in ambienti datati che non lo supportino nativamente, si copi il seguente frammento di codice:

-
// Da 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;
-    };
-  }());
-}
-
-

Si noti che il codice sopra include chiavi non-enumerabili in IE7 (e forse IE8), nel caso in cui si passi un oggetto proveniente da un'altra finestra.

-

Per un semplice polyfill, si veda Javascript - Object.keys Browser Compatibility.

-

Specifiche

- - - - - - - - - - - - - - - - - - -
SpecificaStatoCommento
{{SpecName('ES5.1', '#sec-15.2.3.14', 'Object.keys')}}{{Spec2('ES5.1')}}Definizione iniziale.
- implementato in in JavaScript 1.8.5
{{SpecName('ES6', '#sec-object.keys', 'Object.keys')}}{{Spec2('ES6')}} 
-

Compatibilità dei browser

-
- {{CompatibilityTable}}
-
- - - - - - - - - - - - - - - - - - - -
FeatureFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Supporto base4 (2.0)59125
-
-
- - - - - - - - - - - - - - - - - - - -
FeatureFirefox Mobile (Gecko)AndroidIE MobileOpera MobileSafari Mobile
Supporto base{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
-

Basato su Kangax's compat table.

-

Vedere anche

- diff --git a/files/it/web/javascript/reference/global_objects/object/seal/index.html b/files/it/web/javascript/reference/global_objects/object/seal/index.html deleted file mode 100644 index 4d301b568c..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/seal/index.html +++ /dev/null @@ -1,157 +0,0 @@ ---- -title: Object.seal() -slug: Web/JavaScript/Reference/Global_Objects/Object/seal -tags: - - ECMAScript 5 - - Italian - - Italiano - - JavaScript - - JavaScript 1.8.5 - - Method - - Object -translation_of: Web/JavaScript/Reference/Global_Objects/Object/seal ---- -
{{JSRef}}
- -

Il metodo Object.seal() "sigilla" un oggetto, e ciò rende impossibile l'aggiunta di nuove proprietà e rende tutte le proprietà esistenti non-configurabili. I valori delle proprietà presenti possono comunque essere cambiati, finché sono sovrascrivibili.

- -
{{EmbedInteractiveExample("pages/js/object-prototype-seal.html")}}
- - - -

Sintassi

- -
Object.seal(obj)
- -

Parametri

- -
-
obj
-
L'oggetto da sigillare.
-
- -

Valore di ritorno

- -

L'oggetto sigillato.

- -

Descrizione

- -

Di default, gli oggetti sono {{jsxref("Object.isExtensible()", "estensibili", "", 1)}} (possono essergli aggiunte nuove proprietà). Sigillare un oggetto rende impossibile l'aggiunta di nuove proprietà e rende tutte le proprietà esistenti non-configurabili. Questo rende le proprietà dell'oggetto statiche ed immutabili. Rendere tutte le proprietà non-configurabili, inoltre, rende impossibile la conversione da proprietà "data" a proprietà "accessor" e viceversa, ma non rende impossibile la modifica dei valori delle proprietà "data". Qualsiasi tentativo di aggiungere o rimuovere proprietà ad un oggetto sigillato, o convertire una proprietà "data" in una proprietà "accessor" o viceversa, fallirebbe, o in modo silenzioso o  attraverso il ritorno di un {{jsxref("TypeError")}} (più frequentemente, ma non necessariamente, quest'ultimo scenario accadrebbe in {{jsxref("Strict_mode", "strict mode", "", 1)}}).

- -

Le catene di prototipi non vengono sigillate. Invece, la proprietà {{jsxref("Object.proto", "__proto__")}} {{deprecated_inline}} viene sigillata.

- -

Ritorna l'oggetto passato ma sigillato.

- -

Examples

- -
var obj = {
-  prop: function() {},
-  foo: 'bar'
-};
-
-// Nuove proprietà potrebbero essere aggiunte, proprietà esistenti
-// potrebbero essere modificate o rimosse.
-obj.foo = 'baz';
-obj.lumpy = 'woof';
-delete obj.prop;
-
-var o = Object.seal(obj);
-
-o === obj; // true
-Object.isSealed(obj); // === true
-
-// Cambiare proprietà su un oggetto sigillato
-// è ancora possibile.
-obj.foo = 'quux';
-
-// Ma non puoi convertire proprietà "data" in proprietà "accessor"
-// o viceversa.
-Object.defineProperty(obj, 'foo', {
-  get: function() { return 'g'; }
-}); // genera un TypeError
-
-// Ora, qualunque cambiamento, eccetto i valori delle proprietà,
-// fallirà.
-obj.quaxxor = 'the friendly duck';
-// silenziosamente non aggiunge la proprietà, per cui non genera errori od eccezioni
-delete obj.foo;
-// silenziosamente non rimuove la proprietà, per cui non genera errori od eccezioni
-
-// ...ed in strict mode, aggiungere o rimuovere proprietà
-// genererà TypeErrors.
-function fail() {
-  'use strict';
-  delete obj.foo; // genera un TypeError
-  obj.sparky = 'arf'; // genera un TypeError
-}
-fail();
-
-// Anche aggiungere proprietà tramite
-// Object.defineProperty genererà l'errore.
-Object.defineProperty(obj, 'ohai', {
-  value: 17
-}); // genera un TypeError
-Object.defineProperty(obj, 'foo', {
-  value: 'eit'
-}); // modifica il valore di una proprietà esistente
-
- -

Note

- -

In ES5, se l'argomento di questo metodo non è un'oggetto, allora verrà generato un {{jsxref("TypeError")}}. In ES2015, un argomento che non è un oggetto verrà trattato come se fosse un normale oggetto già sigillato, e verrà perciò semplicemente ritornato.

- -
Object.seal(1);
-// TypeError: 1 non è un oggetto (codice in ES5)
-
-Object.seal(1);
-// 1                             (codice in ES2015)
-
- -

Differenza con Object.freeze()

- -

Le proprietà esistenti in oggetti congelati con Object.freeze() sono rese immutabili. Gli oggetti sigillati con Object.seal() possono ricevere modifiche alle proprietà esistenti.

- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES5.1', '#sec-15.2.3.8', 'Object.seal')}}{{Spec2('ES5.1')}}Definizione iniziale. Implementato in JavaScript 1.8.5.
{{SpecName('ES6', '#sec-object.seal', 'Object.seal')}}{{Spec2('ES6')}}
{{SpecName('ESDraft', '#sec-object.seal', 'Object.seal')}}{{Spec2('ESDraft')}}
- -

Compatibilità con i browser

- -
- - -

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

-
- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/object/tostring/index.html b/files/it/web/javascript/reference/global_objects/object/tostring/index.html deleted file mode 100644 index 5a77ea1a3e..0000000000 --- a/files/it/web/javascript/reference/global_objects/object/tostring/index.html +++ /dev/null @@ -1,170 +0,0 @@ ---- -title: Object.prototype.toString() -slug: Web/JavaScript/Reference/Global_Objects/Object/toString -tags: - - JavaScript - - Method - - Object - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Object/toString ---- -
{{JSRef("Global_Objects", "Object")}}
- -

Sommario

- -

Il metodo toString() restituisce una stringa a che rappresenta l'oggetto.

-
{{EmbedInteractiveExample("pages/js/object-prototype-tostring.html")}}
- - -

Sintassi

- -
obj.toString()
- -

Descrizione

- -

Ogni oggetto ha un metodo toString() che è automaticamente chiamato quando l'oggetto deve essere rappresentato come valore testuale o quando l'oggetto è referenziato in un contesto in cui viene attesa una stringa. Di default, il metodo toString() è ereditato da ogni oggetto che discende da Object. Se il metodo non è sovrascritto in un oggetto personalizzato, toString() restituisce "[object type]", dove type è il tipo di oggetto. Il codice di seguito lo illustra:

- -
var o = new Object();
-o.toString();           // returns [object Object]
-
- -
-

Nota: A partire da JavaScript 1.8.5 toString() richiamato su {{jsxref("Global_Objects/null", "null")}} restituisce [object Null], e {{jsxref("Global_Objects/undefined", "undefined")}} restituisce [object Undefined], come definito nella versione 5 di ECMAScript e nei succcessivi Errata. Vedi {{anch("Example:_Using_toString_to_detect_object_type", "Using toString to detect object type")}}.

-
- -

Esempi

- -

Esempio: Sovrascrittura del metodo di default toString 

- -

Puoi creare una funzione che deve essere richiamata al posto del default metodo toString(). Il metodo toString() non prende argomenti e deve restituire una stringa. Esso può assumere qualunque valore tu voglia, ma sarà molto utile se comunichi informazioni sull'oggetto.

- -

Il codice seguente definisce l'oggetto Dog e crea theDog, ovvero un oggetto di tipo Dog:

- -
function Dog(name, breed, color, sex) {
-  this.name = name;
-  this.breed = breed;
-  this.color = color;
-  this.sex = sex;
-}
-
-theDog = new Dog('Gabby', 'Lab', 'chocolate', 'female');
-
- -

Richiamando il metodo toString() su questo oggetto personalizzato, esso restituisce il valore di default ereditato da {{jsxref("Global_Objects/Object", "Object")}}:

- -
theDog.toString(); // returns [object Object]
-
- -

Il codice seguente crea e assegna il metodo dogToString() per sovrascrivere il metodo di default toString(). Questa funzione genera una stringa contenente i valori name, breed, color e sex dell'oggetto, nella forma di "property = value;".

- -
Dog.prototype.toString = function dogToString() {
-  var ret = 'Dog ' + this.name + ' is a ' + this.sex + ' ' + this.color + ' ' + this.breed;
-  return ret;
-}
-
- -

Col precedente codice, la funzione dogToString() è richiamata automaticamente da JavaScript ogni volta che l'oggetto theDog è usato in un contesto string, e restituisce la seguente stringa:

- -
Dog Gabby is a female chocolate Lab
-
- -

Esempio: Uso di toString() per individuare l'oggetto class

- -

toString() può essere usato con ogni oggetto e permette di ottenere il suo class. Per usare Object.prototype.toString() con ogni oggetto, c'è bisogno di richiamare {{jsxref("Function.prototype.call()")}} o {{jsxref("Function.prototype.apply()")}} su di esso, passando l'oggetto che si cerca di ispezionare come primo parametro chiamato thisArg.

- -
var toString = Object.prototype.toString;
-
-toString.call(new Date);    // [object Date]
-toString.call(new String);  // [object String]
-toString.call(Math);        // [object Math]
-
-// Since JavaScript 1.8.5
-toString.call(undefined);   // [object Undefined]
-toString.call(null);        // [object Null]
-
- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - -
SpecificheStatoCommento
ECMAScript 1 Edizione.StandardDefinizione iniziale. Implementato in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.2.4.2', 'Object.prototype.toString')}}{{Spec2('ES5.1')}}Richiamato su {{jsxref("Global_Objects/null", "null")}} restituisce [object Null], e {{jsxref("Global_Objects/undefined", "undefined")}} restituisce [object Undefined]
{{SpecName('ES6', '#sec-object.prototype.tostring', 'Object.prototype.toString')}}{{Spec2('ES6')}}
- -

Compatibilità browser

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaratteristicheChromeFirefox (Gecko)Internet ExplorerOperaSafari
Support Base{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Support Base{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vedi anche

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