diff options
author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/it/web/javascript/reference/global_objects/object | |
parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip |
remove retired locales (#699)
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/object')
14 files changed, 0 insertions, 2630 deletions
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 ---- -<div>{{JSRef}}</div> - -<h2 id="Sommario">Sommario</h2> - -<p>La funzione <strong><code>Object.assign()</code></strong> copia tutte le proprietà enumerabili da uno o più oggetti di origine in un oggetto di destinazione. Restituisce l'oggetto di destinazione.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox notranslate"><code>Object.assign(<var>target</var>, ...<var>sources</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>target</code></dt> - <dd>L'oggetto di destinazione.</dd> - <dt><code>sources</code></dt> - <dd>Gli oggetti di origine.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>La funzione <code>Object.assign()</code> copia soltanto le proprietà <em>enumerabili</em> appartenenti agli oggetti di origine (non quelle che fanno parte della loro catena dei prototipi) in un oggetto di destinazione. Utilizza <code>[[Get]]</code> sugli oggetti di origine e <code>[[Put]]</code> su quello di destinazione, quindi invoca <em>getter</em> e <em>setter</em>, quando presenti. Quindi <em>assegna</em> 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 <em>getter</em> o <em>setter</em>. Per copiare le proprietà, incluso il fatto di essere enumerabili o no, in un prototipo, bisognerebbe usare {{jsxref("Object.defineProperty()")}}.</p> - -<p>Vengono copiate sia le proprietà aventi come nomi delle {{jsxref("String", "stringhe")}} che dei {{jsxref("Symbol", "simboli")}}.</p> - -<p>In caso di errore, per esempio se una proprietà non è sovrascrivibile, viene generato un {{jsxref("TypeError")}}, e l'oggetto di destinazione rimane invariato.</p> - -<p>Notare che <code>Object.assign()</code> non genera un errore se uno dei valori di origine è {{jsxref("null")}} o {{jsxref("undefined")}}.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Clonare_un_oggetto">Clonare un oggetto</h3> - -<p>Si potrebbe pensare di clonare un oggetto semplicemente assegnandolo ad un altra variabile:</p> - -<pre class="brush: js notranslate">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?</pre> - -<p>Utilizzando <code>Object.assign()</code> il problema non si verifica:</p> - -<pre class="brush: js notranslate">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 } -</pre> - -<h3 id="Unire_più_oggetti">Unire più oggetti</h3> - -<pre class="brush: js notranslate">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 -</pre> - -<h3 id="Copiare_proprietà_aventi_come_indici_dei_simboli">Copiare proprietà aventi come indici dei simboli</h3> - -<pre class="brush: js notranslate">var o1 = { a: 1 }; -var o2 = { [Symbol("foo")]: 2 }; - -var obj = Object.assign({}, o1, o2); -console.log(obj); // { a: 1, Symbol(foo): 2 } -</pre> - -<h3 id="Le_proprietà_ereditate_o_non-enumerabili_non_vengono_copiate">Le proprietà ereditate o non-enumerabili non vengono copiate</h3> - -<pre class="brush: js notranslate">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 } -</pre> - -<h3 id="I_valori_primitivi_vengono_trasformati_in_oggetti">I valori primitivi vengono trasformati in oggetti</h3> - -<pre class="brush: js notranslate">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" } -</pre> - -<h3 id="Se_viene_generata_un_eccezione_la_funzione_si_ferma">Se viene generata un eccezione, la funzione si ferma</h3> - -<pre class="brush: js notranslate">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 -</pre> - -<h3 id="Copiare_i_getter">Copiare i getter</h3> - -<pre class="brush: js notranslate">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 } } -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Questo polyfill non supporta i simboli (che comunque non sono supportati da ECMAScript 5):</p> - -<pre class="brush: js notranslate">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; - } - }); -} -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-object.assign', 'Object.assign')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Definizione iniziale.</td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Funzionalità</th> - <th>Chrome</th> - <th>Edge</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Supporto di base</td> - <td>{{CompatChrome("45")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("34")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatOpera("32")}}</td> - <td>{{CompatSafari("9")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th><span style="font-family: open sans light,sans-serif; font-size: 16px; line-height: 16px;">Funzionalità</span></th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Edge</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td><span style="font-size: 12px; line-height: 18px;">Supporto di base</span></td> - <td>{{CompatNo}}</td> - <td>{{CompatChrome("45")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("34")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Object.defineProperties()")}}</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>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".</p> - -<pre dir="ltr" id="tw-target-rmn"></pre> - - - -<h2 id="Description">Description</h2> - -<pre dir="ltr" id="tw-target-text">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.</pre> - -<pre class="brush: js notranslate">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 -</pre> - -<h2 id="Examples">Examples</h2> - -<h3 id="Displaying_the_constructor_of_an_object">Displaying the constructor of an object</h3> - -<p>The following example creates a constructor (<code>Tree</code>) and an object of that type (<code>theTree</code>). The example then displays the <code>constructor</code> property for the object <code>theTree</code>.</p> - -<pre class="brush: js notranslate">function Tree(name) { - this.name = name -} - -let theTree = new Tree('Redwood') -console.log('theTree.constructor is ' + theTree.constructor) -</pre> - -<p>This example displays the following output:</p> - -<pre class="brush: js notranslate">theTree.constructor is function Tree(name) { - this.name = name -} -</pre> - -<h3 id="Changing_the_constructor_of_an_object">Changing the constructor of an object</h3> - -<p>One can assign the <code>constructor</code> property for any value except <code>null</code> and <code>undefined</code> since those don't have a corresponding constructor function (like <code>String</code>, <code>Number</code>, <code>Boolean</code> 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 <code>null</code> and <code>undefined</code>) 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.</p> - -<pre class="brush: js notranslate">let val = null; -val.constructor = 1; //<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format">TypeError: <span class="objectBox objectBox-string">var is null</span></span></span></span></span> - -<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format"><span class="objectBox objectBox-string">val = 'abc';</span></span></span></span></span> -<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format"><span class="objectBox objectBox-string">val.constructor = Number; //val.constructor === String</span></span></span></span></span> - -<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format"><span class="objectBox objectBox-string">val.foo = 'bar';</span></span></span></span></span> //An implicit instance of <span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format"><span class="objectBox objectBox-string">String('abc') was created and assigned the prop foo</span></span></span></span></span> -<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox-stackTrace reps-custom-format"><span class="objectBox objectBox-string">val.foo === undefined; //true, since a new instance of String('abc') was created for this comparison, which doesn't have the foo property</span></span></span></span></span></pre> - -<p>So basically one can change the value of the <code>constructor</code> property for anything, except the primitives mentioned above, <strong>note that changing the </strong><code>constructor</code><strong> property does not affect the instanceof operator</strong>:</p> - -<pre class="brush: js notranslate">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.</pre> - -<p>If the object is sealed/frozen then the change has no effect and no exception is thrown:</p> - -<pre class="brush: js notranslate">let a = Object.seal({}); -a.constructor = Number; -a.constructor === Object; //true</pre> - -<h3 id="Changing_the_constructor_of_a_function">Changing the constructor of a function</h3> - -<p>Mostly this property is used for defining a function as a <strong>function-constructor</strong> with further calling it with <strong>new</strong> and prototype-inherits chain.</p> - -<pre class="brush: js notranslate">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</pre> - -<p>But when do we need to perform the last line here? Unfortunately, the answer is: <em>it depends</em>.</p> - -<p>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.</p> - -<p>Take the following case: the object has the <code>create()</code> method to create itself.</p> - -<pre class="brush: js notranslate">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</pre> - -<p>In the example above the exception will be shown since the constructor links to Parent.</p> - -<p>To avoid this, just assign the necessary constructor you are going to use.</p> - -<pre class="brush: js notranslate">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</pre> - -<p>Ok, now it's pretty clear why changing the constructor can be useful.</p> - -<p>Let's consider one more case.</p> - -<pre class="brush: js notranslate">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 - } -};</pre> - -<p>For this example we need either to stay parent constructor to continue to work properly or reassign static properties to child's constructor:</p> - -<pre class="brush: js notranslate">... -Child = Object.assign(ParentWithStatic) // Notice that we assign it before we create(...) a prototype below -Child.prototype = Object.create(ParentWithStatic.prototype) -... -</pre> - -<p>or assign parent constructor identifier to a separate property on the Child constructor function and access it via that property:</p> - -<pre class="brush: js notranslate">... -Child.parentConstructor = ParentWithStatic -Child.prototype = Object.create(ParentWithStatic.prototype) -... - let startPosition = this.constructor.parentConstructor.getStartPosition() -... -</pre> - -<div class="blockIndicator note"> -<p><strong>Summary</strong>: Manually updating or setting the constructor can lead to differrent and sometimes confusing consequences. To prevent this, just define the role of <code>constructor</code> in each specific case. In most cases, <code>constructor</code> is not used and reassignment of it is not necessary.</p> -</div> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specification</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.prototype.constructor', 'Object.prototype.constructor')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - - - -<p>{{Compat("javascript.builtins.Object.constructor")}}</p> - -<h2 id="See_also">See also</h2> - -<div class="hidden"> -<p>The curly braces here invoke standard macroses defined by the MDN wiki. Checkout here for more info: <a href="/en-US/docs/MDN/Contribute/Structures/Macros/Commonly-used_macros">https://developer.mozilla.org/en-US/docs/MDN/Contribute/Structures/Macros/Commonly-used_macros</a></p> -</div> - -<ul> - <li>{{jsxref("statements/class","Class declaration","",1)}}</li> - <li>{{jsxref("Classes/constructor","Class constructor","",1)}}</li> - <li>Glossary: {{Glossary("constructor", "", 1)}}</li> -</ul> 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 ---- -<div> - {{JSRef("Global_Objects", "Object")}}</div> -<h2 id="Summary" name="Summary">Sommario</h2> -<p>Il metodo <code><strong>Object.create()</strong></code> crea un nuovo oggetto a partire dall'oggetto prototipo e dalle proprietà specificati.</p> -<h2 id="Syntax" name="Syntax">Sintassi</h2> -<pre class="syntaxbox"><code>Object.create(<var>proto</var>[, <var>propertiesObject</var>])</code></pre> -<h3 id="Parameters" name="Parameters">Parametri</h3> -<dl> - <dt> - <code>proto</code></dt> - <dd> - L'oggetto che farà da prototipo per il nuovo oggetto creato.</dd> - <dt> - <code>propertiesObject</code></dt> - <dd> - 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()")}}.</dd> -</dl> -<h3 id="Throws" name="Throws">Throws</h3> -<p>Lancia un'eccezione di tipo {{jsxref("Global_Objects/TypeError", "TypeError")}} se il parametro <code>proto</code> non è {{jsxref("Global_Objects/null", "null")}} oppure un oggetto.</p> -<h2 id="Examples" name="Examples">Esempi</h2> -<h3 id="Example:_Classical_inheritance_with_Object.create" name="Example:_Classical_inheritance_with_Object.create">Esempio: ereditarietà classica con <code>Object.create</code></h3> -<p>Sotto, trovi un esempio di come implementare un'ereditarietà classica usando <code>Object.create</code>. Si tratta di un'ereditarietà singola, l'unica supportata da Javascript.</p> -<pre class="brush: js">// 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<span style="font-size: 1rem;">? " + (rect instanceof Shape)); // true</span> - -rect.move(1, 1); // Outputs, 'Shape moved.' -</pre> -<p>Se desideri ereditare proprietà e metodi da oggetti multipli, puoi utilizzare dei mixins.</p> -<pre class="brush: js">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 -}; -</pre> -<p>La funzione <code>mixin</code> 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 <a href="http://api.jquery.com/jQuery.extend/">jQuery.extend</a>.</p> -<h3 id="Example:_Using_propertiesObject_argument_with_Object.create" name="Example:_Using_propertiesObject_argument_with_Object.create">Esempio: Usare l'argomento <code>propertiesObject</code> con <code>Object.create</code></h3> -<pre class="brush: js">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 - } -}); -</pre> -<h2 id="Polyfill" name="Polyfill">Polyfill</h2> -<p>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.</p> -<pre class="brush: js">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; - }; - })(); -} -</pre> -<h2 id="Specifications" name="Specifications">Specifiche</h2> -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.5', 'Object.create')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definizione iniziale. Implementato in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.create', 'Object.create')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> -<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilità browser</h2> -<div> - {{CompatibilityTable}}</div> -<div id="compat-desktop"> - <table class="compat-table"> - <tbody> - <tr> - <th>Caratteristica</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Supporto base</td> - <td>{{CompatChrome("5")}}</td> - <td>{{CompatGeckoDesktop("2")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("11.60")}}</td> - <td>{{CompatSafari("5")}}</td> - </tr> - </tbody> - </table> -</div> -<div id="compat-mobile"> - <table class="compat-table"> - <tbody> - <tr> - <th>Caratteristica</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Supporto base</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("2")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatOperaMobile("11.50")}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> - </table> -</div> -<p>Basato sulla <a href="http://kangax.github.com/es5-compat-table/">tabella di compatibilità di Kangax</a>.</p> -<h2 id="See_also" name="See_also">Vedi anche</h2> -<ul> - <li>{{jsxref("Object.defineProperty")}}</li> - <li>{{jsxref("Object.defineProperties")}}</li> - <li>{{jsxref("Object.prototype.isPrototypeOf")}}</li> - <li>Il post di John Resig su <a href="http://ejohn.org/blog/objectgetprototypeof/">getPrototypeOf</a></li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <strong>Object.defineProperties()</strong> definisce nuove proprietà o modifica le proprietà esistenti, direttamente sull'oggetto di ritorno.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>Object.defineProperties(<var>obj</var>, <var>props</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto su cui definire le nuove proprietà o modificare le esistenti proprietà.</dd> - <dt><code>props</code></dt> - <dd>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:</dd> - <dd> - <dl> - <dt><code>configurable</code></dt> - <dd><code>true</code> se e solo se la proprietà individuata dal descrittore può essere cambiata e se la proprietà può essere cancellata dal presente oggetto.<br> - <strong>Defaults a <code>false</code>.</strong></dd> - <dt><code>enumerable</code></dt> - <dd><code>true</code> se e solo se la proprietà è visualizzabile durante una enumerazione delle proprietà del presente oggetto (es. for-in)<br> - <strong>Defaults a <code>false</code>.</strong></dd> - </dl> - - <dl> - <dt><code>value</code></dt> - <dd>Il valore associato con la proprietà che si sta definendo. Può essere un qualsiasi valore valido di Javascript (number, object, function, ecc...)<br> - <strong>Defaults a {{jsxref("undefined")}}.</strong></dd> - <dt><code>writable</code></dt> - <dd><code>true</code> se e solo se il valore associato per la proprietà può essere cambiato con un {{jsxref("Operators/Assignment_Operators", "operatore di assegnazione", "", 1)}}.<br> - <strong>Defaults to <code>false</code>.</strong></dd> - </dl> - - <dl> - <dt><code>get</code></dt> - <dd>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à<br> - <strong>Defaults a {{jsxref("undefined")}}.</strong></dd> - <dt><code>set</code></dt> - <dd>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à.<br> - <strong>Defaults a {{jsxref("undefined")}}.</strong></dd> - </dl> - </dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>L'oggetto che è stato passato alla funzione.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p><code>Object.defineProperties</code>, in sostanza, definisce tutte le proprietà di un oggetto, corrispondenti alle proprietà "own" proprie di un oggetto obj.</p> - -<h2 id="Esempio">Esempio</h2> - -<pre class="brush: js">var obj = {}; -Object.defineProperties(obj, { - 'property1': { - value: true, - writable: true - }, - 'property2': { - value: 'Hello', - writable: false - } - // etc. etc. -}); -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Assumendo di eseguire un ambiente precedente con tutti i nomi e le proprietà che fanno riferimento ai valori iniziali, <code>Object.defineProperties</code> è quasi completamente equivalente (nota il commento in <code>isCallable</code>) al seguente reimplementazione in Javascript:</p> - -<pre class="brush: js;highlight:[8]">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; -} -</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.7', 'Object.defineProperties')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initial definition. Implemented in JavaScript 1.8.5</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.defineproperties', 'Object.defineProperties')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.defineproperties', 'Object.defineProperties')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Firefox (Gecko)</th> - <th>Chrome</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatGeckoDesktop("2")}}</td> - <td>{{CompatChrome("5")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("11.60")}}</td> - <td>{{CompatSafari("5")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Firefox Mobile (Gecko)</th> - <th>Android</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatGeckoMobile("2")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatOperaMobile("11.5")}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Object.defineProperty()")}}</li> - <li>{{jsxref("Object.keys()")}}</li> - <li><a href="/en-US/docs/Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a></li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.freeze()</strong></code> 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. </p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>Object.freeze(<var>obj</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto da congelare.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>L'oggetto passato alla funzione.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>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)}}).</p> - -<p>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.</p> - -<h2 id="Esempi">Esempi</h2> - -<pre class="brush: js">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 -</pre> - -<p>Il seguente esempio mostra come oggetti che sono valori di proprietà possono essere mutati(il congelamento si ferma ad un solo livello di profondità).</p> - -<pre class="brush: js">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 -</pre> - -<h2 id="Note">Note</h2> - -<p>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.</p> - -<pre class="brush: js">> Object.freeze(1) -TypeError: 1 is not an object // ES5 code - -> Object.freeze(1) -1 // ES2015 code -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.9', 'Object.freeze')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Commento iniziale. Implementato in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-object.freeze', 'Object.freeze')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.freeze', 'Object.freeze')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Funzionalità</th> - <th>Firefox (Gecko)</th> - <th>Chrome</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Funzionalità di base</td> - <td>{{CompatGeckoDesktop("2")}}</td> - <td>{{CompatChrome("6")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("12")}}</td> - <td>{{CompatSafari("5.1")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Funzionalità</th> - <th>Firefox Mobile (Gecko)</th> - <th>Android</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Funzionalità di base</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li>{{jsxref("Object.isFrozen()")}}</li> - <li>{{jsxref("Object.preventExtensions()")}}</li> - <li>{{jsxref("Object.isExtensible()")}}</li> - <li>{{jsxref("Object.seal()")}}</li> - <li>{{jsxref("Object.isSealed()")}}</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.getPrototypeOf()</strong></code> restituisce il prototipo (ovvero il valore della proprietà interna <code>[[Prototype]]</code>) dell'oggetto specificato.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>Object.getPrototypeOf(<var>obj</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto di cui si vuole ottenere il prototipo.</dd> -</dl> - -<h2 id="Esempi">Esempi</h2> - -<pre class="brush: js">var proto = {}; -var obj = Object.create(proto); -Object.getPrototypeOf(obj) === proto; // true -</pre> - -<h2 id="Note">Note</h2> - -<p>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")}}.</p> - -<pre class="brush: js">Object.getPrototypeOf("foo"); -// TypeError: "foo" is not an object (ES5 code) -Object.getPrototypeOf("foo"); -// String.prototype (ES6 code) -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.2', 'Object.getPrototypeOf')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Prima definizione.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.getprototypeof', 'Object.getProtoypeOf')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_fra_i_Browser">Compatibilità fra i Browser</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatChrome("5")}}</td> - <td>{{CompatGeckoDesktop("1.9.1")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("12.10")}}</td> - <td>{{CompatSafari("5")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Note_specifiche_su_Opera">Note specifiche su Opera</h2> - -<p>Anche se le vecchie versioni di Opera non supportano ancora il metodo <code>Object.getPrototypeOf()</code>, comunque dalla versione 10.50 è stata implementata la proprietà non standard {{jsxref("Object.proto", "__proto__")}}.</p> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li>{{jsxref("Object.prototype.isPrototypeOf()")}}</li> - <li>{{jsxref("Object.setPrototypeOf()")}} {{experimental_inline}}</li> - <li>{{jsxref("Object.prototype.__proto__")}}</li> - <li>Il post di John Resig su <a class="external" href="http://ejohn.org/blog/objectgetprototypeof/">getPrototypeOf</a></li> - <li>{{jsxref("Reflect.getPrototypeOf()")}}</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <strong><code>hasOwnProperty()</code></strong> restituisce un valore booleano che indica se l'oggetto ha la proprietà specificata come propria proprietà (invece di ereditarla).</p> - -<div>{{EmbedInteractiveExample("pages/js/object-prototype-hasownproperty.html")}}</div> - - - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><var>obj</var>.hasOwnProperty(<var>prop</var>)</pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><var>prop</var></dt> - <dd>Il nome della {{jsxref("String")}} o il {{Glossary("Symbol")}} della proprietà da testare.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>Un {{jsxref("Boolean")}} che indica se l'oggetto ha o meno la proprietà specificata come proprietà propria.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Tutti i discendenti di {{jsxref("Object")}} ereditano il metodo <code>hasOwnProperty</code>. 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.</p> - -<h2 id="Note">Note</h2> - -<p><code>hasOwnProperty</code> restituisce true anche se il valore della proprietà è <code>null</code> o <code>undefined</code>.</p> - -<pre class="brush: js">o = new Object(); -o.propOne = null; -o.hasOwnProperty('propOne'); // ritorna true -o.propTwo = undefined; -o.hasOwnProperty('propTwo'); // ritorna true -</pre> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Usare_hasOwnProperty_per_verificare_l'esistenza_di_una_proprietà">Usare <code>hasOwnProperty</code> per verificare l'esistenza di una proprietà</h3> - -<p>L'esempio seguente determina se l'oggetto o contiene una proprietà denominata <code>prop</code>:</p> - -<pre class="brush: js">o = new Object(); -o.hasOwnProperty('prop'); // ritorna false -o.prop = 'exists'; -o.hasOwnProperty('prop'); // ritorna true -</pre> - -<h3 id="Dirette_vs._proprietà_ereditate">Dirette vs. proprietà ereditate</h3> - -<p>Il seguente esempio distingue tra proprietà dirette e proprietà ereditate attraverso la catena del prototipo:</p> - -<pre class="brush: js">o = new Object(); -o.prop = 'exists'; -o.hasOwnProperty('prop'); // ritorna true -o.hasOwnProperty('toString'); // ritorna false -o.hasOwnProperty('hasOwnProperty'); // ritorna false -</pre> - -<h3 id="Iterare_sulle_proprietà_di_un_oggetto">Iterare sulle proprietà di un oggetto</h3> - -<p>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 <code>hasOwnProperty</code> è strettamente limitato agli elementi enumerabili (come con {{jsxref("Object.getOwnPropertyNames()")}}).</p> - -<pre class="brush: js">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 - } -} -</pre> - -<h3 id="Usare_hasOwnProperty_come_nome_di_una_proprietà">Usare <code>hasOwnProperty</code> come nome di una proprietà</h3> - -<p>JavaScript non protegge il nome della proprietà <code>hasOwnProperty</code>; quindi, se esiste la possibilità che un oggetto possa avere una proprietà con questo nome, è necessario utilizzare un <code>hasOwnProperty</code> <em>esterno</em> per ottenere risultati corretti:</p> - -<pre class="brush: js">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 -</pre> - -<p>Nota che nell'ultimo caso non ci sono oggetti appena creati.</p> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.prototype.hasownproperty', 'Object.prototype.hasOwnProperty')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.4.5', 'Object.prototype.hasOwnProperty')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Definizione iniziale Implementato in JavaScript 1.5.</td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - - - -<p>{{Compat("javascript.builtins.Object.hasOwnProperty")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li><a href="/en-US/docs/Enumerability_and_ownership_of_properties">Enumerabilità e proprietà delle proprietà</a></li> - <li>{{jsxref("Object.getOwnPropertyNames()")}}</li> - <li>{{jsxref("Statements/for...in", "for...in")}}</li> - <li>{{jsxref("Operators/in", "in")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain">Guida JavaScript: Ereditarietà rivisitata</a></li> -</ul> 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 ---- -<div>{{JSRef("Global_Objects", "Object")}}</div> - -<h2 id="Summary" name="Summary">Sommari</h2> - -<p>Il costruttore <strong>Object</strong> crea un oggetto.</p> - -<h2 id="Syntax" name="Syntax">Sintassi</h2> - -<pre class="syntaxbox"><code><code>// Letterale -{ <em>[ coppiaNomeValore1 [, </em></code></code>coppiaNomeValore<code><code><em>2 [, ...</em></code></code>coppiaNomeValore<code><code><em>N] ] ]</em> } - -// Richiamato come una classe -</code>new Object( <em>[ value ]</em> )</code></pre> - -<h3 id="Parameters" name="Parameters">Parametri</h3> - -<dl> - <dt>coppiaNomeValore1, coppiaNomeValore2, ... coppiaNomeValoreN</dt> - <dd>Coppie formate da un nome (una stringa) e un valore (di qualsiasi tipo), dove il nome è separato dal valore con i due punti.</dd> - <dd> - <pre class="brush: js">{ - "nome1": "valore1", - nome2: "valore2" // Gli apici nel nome sono opzionali -}; -</pre> - </dd> -</dl> - -<dl> - <dt>value</dt> - <dd>Qualsiasi valore.</dd> -</dl> - -<h2 id="Description" name="Description">Descrizione</h2> - -<p>Il costruttore <code>Object</code> 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.</p> - -<p>Quando richiamato come normale funzione, il comportamento di <code>Object()</code> è identico a <code>new Object()</code>.</p> - -<h2 id="Properties" name="Properties">Proprietà del costruttore <code>Object</code></h2> - -<dl> - <dt><code>Object.length</code></dt> - <dd>Ha valore pari a <code>1</code>.</dd> - <dt>{{jsxref("Object.prototype")}}</dt> - <dd>Permette di aggiungere altre proprietà ad ogni oggetto di tipo <code>Object</code>.</dd> -</dl> - -<p>{{ jsOverrides("Function", "Properties", "prototype") }}</p> - -<h2 id="Methods" name="Methods">Metodi del costruttore <code>Object</code></h2> - -<dl> - <dt>{{jsxref("Object.assign()")}} {{experimental_inline}}</dt> - <dd>Crea un nuovo oggetto copiando i valori di tutti le proprietà enumerabili da uno o più oggetti.</dd> - <dt>{{jsxref("Object.create()")}}</dt> - <dd>Crea un nuovo oggetto utilizzando il prototipo e le proprietà specificate.</dd> - <dt>{{jsxref("Object.defineProperty()")}}</dt> - <dd>Aggiunge una proprietà descritta dall'oggetto specificato.</dd> - <dt>{{jsxref("Object.defineProperties()")}}</dt> - <dd>Aggiunge più proprietà descritte dall'oggetto specificato.</dd> - <dt>{{jsxref("Object.freeze()")}}</dt> - <dd>Congela un oggetto: le sue proprietà non possono più essere cancellate o modificate.</dd> - <dt>{{jsxref("Object.getOwnPropertyDescriptor()")}}</dt> - <dd>Restituisce un oggetto che descriva la proprietà specificata.</dd> - <dt>{{jsxref("Object.getOwnPropertyNames()")}}</dt> - <dd>Restituisce un array contenente i nomi di tutte le proprietà (enumerabili e non-enumerabili) dell'oggetto specificato.</dd> - <dt>{{jsxref("Object.getPrototypeOf()")}}</dt> - <dd>Restituisce il prototipo dell'oggetto specificato.</dd> - <dt>{{jsxref("Object.is()")}} {{ experimental_inline() }}</dt> - <dd>Determina se due valori sono o no uguali (quindi lo stesso oggetto).</dd> - <dt>{{jsxref("Object.isExtensible()")}}</dt> - <dd>Determina se è permesso estendere un oggetto.</dd> - <dt>{{jsxref("Object.isFrozen()")}}</dt> - <dd>Determina se un oggetto è stato congelato.</dd> - <dt>{{jsxref("Object.isSealed()")}}</dt> - <dd>Determina se un oggetto è stato sigillato.</dd> - <dt>{{jsxref("Object.keys()")}}</dt> - <dd>Restituisce un array contenente i nomi di tutte le proprietà enumerabili dell'oggetto.</dd> - <dt>{{jsxref("Object.observe()")}} {{experimental_inline}}</dt> - <dd>Osserva i cambiamenti di un oggetto in modo asincrono.</dd> - <dt>{{jsxref("Object.preventExtensions()")}}</dt> - <dd>Impedisce ad un oggetto di essere esteso.</dd> - <dt>{{jsxref("Object.seal()")}}</dt> - <dd>Impedisce di eliminare le proprietà di un oggetto.</dd> - <dt>{{jsxref("Object.setPrototypeOf()")}} {{experimental_inline}}</dt> - <dd> - <p>Imposta i prototipo (quindi la proprietà intena <code>[[Prototype]]</code>) di un oggetto.</p> - </dd> -</dl> - -<p>{{jsOverrides("Function", "Methods", "create", "defineProperty", "defineProperties", "getOwnPropertyDescriptor", "getPrototypeOf")}}</p> - -<h2 id="Object_instances" name="Object_instances">Instanze di <code>Object</code> e l'oggetto prototipo <code>Object</code></h2> - -<p>In JavaScript, tutti gli oggetti sono discendenti di <code>Object</code>; 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à <code>constructor</code> e forniscono un loro metodo <code>toString()</code>. I cambiamenti al prototipo di <code>Object</code> venogno estesi a tutti gli oggetti, eccetto quelli che sovrascrivono le proprietà e i metodi cambiati.</p> - -<h3 id="Properties_of_Object_instances" name="Properties_of_Object_instances">Poprietà</h3> - -<p>{{page('/it/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}</p> - -<h3 id="Methods_of_Object_instances" name="Methods_of_Object_instances">Metodi</h3> - -<p>{{page('/it/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}</p> - -<h2 id="Examples" name="Examples">Esempi</h2> - -<h3 id="Usare_Object_con_i_valori_null_e_undefined">Usare <code>Object</code> con i valori <code>null</code> e <code>undefined</code></h3> - -<p>Questi esempi restituiscono tutti lo stesso oggetto:</p> - -<pre class="brush: js">var o = {};</pre> - -<pre class="brush: js">var o = new Object(); -</pre> - -<pre class="brush: js">var o = new Object(undefined); -</pre> - -<pre class="brush: js">var o = new Object(null); -</pre> - -<h3 id="Usare_Object_per_creare_oggetti_Boolean">Usare <code>Object</code> per creare oggetti <code>Boolean</code></h3> - -<p>I seguenti esempi assegnano alla variabile <code>o</code> un oggetto {{jsxref("Global_Objects/Boolean", "Boolean")}}:</p> - -<pre class="brush: js">var o = new Object(true); -// Equivalente a new Boolean(true)</pre> - -<pre class="brush: js">var o = new Object(Boolean()); -// Equivalente a new Boolean(false)</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>ECMAScript 1st Edition. Implemented in JavaScript 1.0</td> - <td>Standard</td> - <td>Definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2', 'Object')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object-objects', 'Object')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<p>{{ CompatibilityTable() }}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Funzionalità</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Supporto di base</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th><span style="font-family: 'Open Sans Light',sans-serif; font-size: 16px; line-height: 16px;">Funzionalità</span></th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td><span style="font-size: 12px; line-height: 18px;">Supporto di base</span></td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - </tr> - </tbody> -</table> -</div> - -<p> </p> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.is()</strong></code> determina se i due parametri di input hanno lo <a href="/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness"> stesso valore</a>.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>Object.is(<var>value1</var>, <var>value2</var>);</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>value1</code></dt> - <dd>Il primo valore da comparare.</dd> - <dt><code>value2</code></dt> - <dd>Il secondo valore da comparare.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>A {{jsxref("Boolean")}} indicating whether or not the two arguments are the same value.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p><code>Object.is()</code> determina se <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness">due valori sono uguali</a>. Due valori sono uguali se sono :</p> - -<ul> - <li>entrambi {{jsxref("undefined")}}</li> - <li>entrambi {{jsxref("null")}}</li> - <li>entrambi <code>true</code> o entrambi <code>false</code></li> - <li>entrambi stringhe della stessa lunghezza con gli stessi caratteri</li> - <li>entrambi lo stesso oggetto</li> - <li>entrambi numeri ed - <ul> - <li>entrambi <code>+0</code></li> - <li>entrambi <code>-0</code></li> - <li>entrambi {{jsxref("NaN")}}</li> - <li>o entrambi non sono 0 ed entrambi non sono {{jsxref("NaN")}} ed entrambi hanno lo stesso valore</li> - </ul> - </li> -</ul> - -<p>Questo <em>non</em> è 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, <code>"" == false</code> risultando <code>true</code>), ma <code>Object.is</code> non converte i loro valori.</p> - -<p>Inoltre questo <em>non</em> è 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 <code>-0</code> e <code>+0</code> come uguali e trattano {{jsxref("Number.NaN")}} differentemente da {{jsxref("NaN")}}.</p> - -<h2 id="Esempi">Esempi</h2> - -<pre class="brush: js">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 -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js">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; - } - }; -}</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-object.is', 'Object.is')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.is', 'Object.is')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_coi_browser">Compatibilità coi browser</h2> - -<div> -<div class="hidden">La compatibility table su questa pagina è generata da dati strutturali. Se vuoi contribuire per i dati, puoi visitare <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> ed inviarci una pull request.</div> - -<p>{{Compat("javascript.builtins.Object.is")}}</p> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness">Equality comparisons and sameness</a> (in inglese) — un paragone di tutte e tre le facilitazioni per comparare uguaglianze</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.isFrozen()</strong></code> determina se un oggetto è {{jsxref("Object.freeze()", "congelato", "", 1)}}.</p> - -<div>{{EmbedInteractiveExample("pages/js/object-isfrozen.html")}}</div> - -<p class="hidden">Il codice sorgente per questo esempio interattivo si trova in una repository di GitHub. Se vuoi contribuire al progetto degli esempi interattivi, puoi clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> ed inviarci una pull request.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>Object.isFrozen(<var>obj</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto da controllare.</dd> -</dl> - -<h3 id="Valori_di_ritorno">Valori di ritorno</h3> - -<p>Un {{jsxref("Boolean")}} che indica se l'oggetto è congelato oppure no.</p> - -<h2 id="Description">Description</h2> - -<p>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.</p> - -<h2 id="Esempi">Esempi</h2> - -<pre class="brush: js">// 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 -</pre> - -<h2 id="Note">Note</h2> - -<p>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 <code>true</code>.</p> - -<pre class="brush: js">Object.isFrozen(1); -// TypeError: 1 non è un oggetto (codice in ES5) - -Object.isFrozen(1); -// true (codice in ES2015) -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.12', 'Object.isFrozen')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definizione iniziale. Implementato in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.isfrozen', 'Object.isFrozen')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.isfrozen', 'Object.isFrozen')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<div> -<div class="hidden">La compatibility table su questa pagina è generata da dati strutturali. Se vuoi contribuire per i dati, puoi visitare <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> ed inviarci una pull request.</div> - -<p>{{Compat("javascript.builtins.Object.isFrozen")}}</p> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Object.freeze()")}}</li> - <li>{{jsxref("Object.preventExtensions()")}}</li> - <li>{{jsxref("Object.isExtensible()")}}</li> - <li>{{jsxref("Object.seal()")}}</li> - <li>{{jsxref("Object.isSealed()")}}</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.isSealed()</strong></code> determina se un oggetto è sigillato.</p> - -<div>{{EmbedInteractiveExample("pages/js/object-issealed.html")}}</div> - -<p class="hidden">Il codice sorgente per questo esempio interattivo si trova in una repository di GitHub. Se vuoi contribuire al progetto degli esempi interattivi, puoi clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> ed inviarci una pull request.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>Object.isSealed(<var>obj</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto da controllare.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>Un {{jsxref("Boolean")}} che indica se l'oggetto è congelato oppure no.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Ritorna <code>true</code> se l'oggetto è sigillato, altrimenti <code>false</code>. 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).</p> - -<h2 id="Esempi">Esempi</h2> - -<pre class="brush: js">// 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à) -</pre> - -<h2 id="Note">Note</h2> - -<p>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 <code>true</code>.</p> - -<pre class="brush: js">Object.isSealed(1); -// TypeError: 1 non è un oggetto (codice in ES5) - -Object.isSealed(1); -// true (codice in ES2015) -</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.11', 'Object.isSealed')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definizione iniziale. Implementato in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.issealed', 'Object.isSealed')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.issealed', 'Object.isSealed')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<div> -<div class="hidden">Il codice sorgente per questo esempio interattivo si trova in una repository di GitHub. Se vuoi contribuire al progetto degli esempi interattivi, puoi clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> ed inviarci una pull request.</div> - -<p>{{Compat("javascript.builtins.Object.isSealed")}}</p> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Object.seal()")}}</li> - <li>{{jsxref("Object.preventExtensions()")}}</li> - <li>{{jsxref("Object.isExtensible()")}}</li> - <li>{{jsxref("Object.freeze()")}}</li> - <li>{{jsxref("Object.isFrozen()")}}</li> -</ul> 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 ---- -<div> - {{JSRef("Global_Objects", "Object")}}</div> -<h2 id="Summary" name="Summary">Sommario</h2> -<p>Il metodo <code><strong>Object.keys()</strong></code> restituisce un array contenente le proprietà enumerabili di un dato oggetto, nel medesimo ordine fornito da un ciclo <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> (la differenza è che un ciclo for-in enumera anche le proprietà nella catena di prototipi).</p> -<h2 id="Syntax" name="Syntax">Sintassi</h2> -<pre class="syntaxbox"><code>Object.keys(<em>obj</em>)</code></pre> -<h3 id="Parameters" name="Parameters">Parametri</h3> -<dl> - <dt> - <em>obj</em></dt> - <dd> - L'oggetto del quale si devono restituire le proprietà enumerabili.</dd> -</dl> -<h2 id="Description" name="Description">Descrizione</h2> -<p><code>Object.keys</code> restituisce un array i quali elementi sono stringhe corrispondenti alle proprietà enumerabili trovate direttamente in <code>obj</code>. L'ordine delle proprietà è lo stesso di quello dato ciclando manualmente sulle proprietà dell'oggetto.</p> -<h2 id="Esempi">Esempi</h2> -<pre class="brush: js">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 -</pre> -<p>Per ottenere tutte le proprietà, anche quelle non enumerabili, si veda {{jsxref("Object.getOwnPropertyNames")}}.</p> -<h2 id="Polyfill">Polyfill</h2> -<p>Per aggiungere un supporto equivalente a <code>Object.keys,</code> in ambienti datati che non lo supportino nativamente, si copi il seguente frammento di codice:</p> -<pre class="brush: js">// 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; - }; - }()); -} -</pre> -<p>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.</p> -<p>Per un semplice polyfill, si veda <a href="http://tokenposts.blogspot.com.au/2012/04/javascript-objectkeys-browser.html">Javascript - Object.keys Browser Compatibility</a>.</p> -<h2 id="Specifiche">Specifiche</h2> -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.14', 'Object.keys')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definizione iniziale.<br> - implementato in in JavaScript 1.8.5</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.keys', 'Object.keys')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> -<h2 id="Compatibilità_dei_browser">Compatibilità dei browser</h2> -<div> - {{CompatibilityTable}}</div> -<div id="compat-desktop"> - <table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Firefox (Gecko)</th> - <th>Chrome</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Supporto base</td> - <td>4 (2.0)</td> - <td>5</td> - <td>9</td> - <td>12</td> - <td>5</td> - </tr> - </tbody> - </table> -</div> -<div id="compat-mobile"> - <table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Firefox Mobile (Gecko)</th> - <th>Android</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Supporto base</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> - </table> -</div> -<p>Basato su <a href="http://kangax.github.com/es5-compat-table/">Kangax's compat table</a>.</p> -<h2 id="See_also" name="See_also">Vedere anche</h2> -<ul> - <li><a href="/en-US/docs/Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a></li> - <li>{{jsxref("Object.prototype.propertyIsEnumerable")}}</li> - <li>{{jsxref("Object.create")}}</li> - <li>{{jsxref("Object.getOwnPropertyNames")}}</li> -</ul> 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 ---- -<div>{{JSRef}}</div> - -<p>Il metodo <code><strong>Object.seal()</strong></code> "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.</p> - -<div>{{EmbedInteractiveExample("pages/js/object-prototype-seal.html")}}</div> - -<p class="hidden">Il codice sorgente per questo esempio interattivo si trova in una repository di GitHub. Se vuoi contribuire al progetto degli esempi interattivi, puoi clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> ed inviarci una pull request.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>Object.seal(<var>obj</var>)</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>L'oggetto da sigillare.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>L'oggetto sigillato.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>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)}}).</p> - -<p>Le catene di prototipi non vengono sigillate. Invece, la proprietà {{jsxref("Object.proto", "__proto__")}} {{deprecated_inline}} viene sigillata.</p> - -<p>Ritorna l'oggetto passato ma sigillato.</p> - -<h2 id="Examples">Examples</h2> - -<pre class="brush: js">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 -</pre> - -<h2 id="Note">Note</h2> - -<p>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.</p> - -<pre class="brush: js">Object.seal(1); -// TypeError: 1 non è un oggetto (codice in ES5) - -Object.seal(1); -// 1 (codice in ES2015) -</pre> - -<h3 id="Differenza_con_Object.freeze">Differenza con <code>Object.freeze()</code></h3> - -<p>Le proprietà esistenti in oggetti congelati con <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze">Object.freeze()</a></code> sono rese immutabili. Gli oggetti sigillati con <code>Object.seal()</code> possono ricevere modifiche alle proprietà esistenti.</p> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.3.8', 'Object.seal')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definizione iniziale. Implementato in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.seal', 'Object.seal')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object.seal', 'Object.seal')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<div> -<div class="hidden">La compatibility table su questa pagina è generata da dati strutturali. Se vuoi contribuire per i dati, puoi visitare <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> ed inviarci una pull request.</div> - -<p>{{Compat("javascript.builtins.Object.seal")}}</p> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Object.isSealed()")}}</li> - <li>{{jsxref("Object.preventExtensions()")}}</li> - <li>{{jsxref("Object.isExtensible()")}}</li> - <li>{{jsxref("Object.freeze()")}}</li> - <li>{{jsxref("Object.isFrozen()")}}</li> -</ul> 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 ---- -<div>{{JSRef("Global_Objects", "Object")}}</div> - -<h2 id="Summary" name="Summary">Sommario</h2> - -<p>Il metodo <code><strong>toString()</strong></code> restituisce una stringa a che rappresenta l'oggetto.</p> -<div>{{EmbedInteractiveExample("pages/js/object-prototype-tostring.html")}}</div> - -<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div> -<h2 id="Syntax" name="Syntax">Sintassi</h2> - -<pre class="syntaxbox notranslate"><code><var>obj</var>.toString()</code></pre> - -<h2 id="Description" name="Description">Descrizione</h2> - -<p>Ogni oggetto ha un metodo <code>toString()</code> 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 <code>toString()</code> è ereditato da ogni oggetto che discende da <code>Object</code>. Se il metodo non è sovrascritto in un oggetto personalizzato, <code>toString()</code> restituisce "[object <em>type</em>]", dove <code><em>type</em></code> è il tipo di oggetto. Il codice di seguito lo illustra:</p> - -<pre class="brush: js notranslate">var o = new Object(); -o.toString(); // returns [object Object] -</pre> - -<div class="note"> -<p><strong>Nota:</strong> A partire da JavaScript 1.8.5 <code>toString()</code> richiamato su {{jsxref("Global_Objects/null", "null")}} restituisce <code>[object <em>Null</em>]</code>, e {{jsxref("Global_Objects/undefined", "undefined")}} restituisce <code>[object <em>Undefined</em>]</code>, 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")}}.</p> -</div> - -<h2 id="Examples" name="Examples">Esempi</h2> - -<h3 id="Example_Overriding_the_default_toString_method" name="Example:_Overriding_the_default_toString_method">Esempio: Sovrascrittura del metodo di default <code>toString</code> </h3> - -<p>Puoi creare una funzione che deve essere richiamata al posto del default metodo <code>toString()</code>. Il metodo <code>toString()</code> non prende argomenti e deve restituire una stringa. Esso può assumere qualunque valore tu voglia, ma sarà molto utile se comunichi informazioni sull'oggetto.</p> - -<p>Il codice seguente definisce l'oggetto <code>Dog</code> e crea <code>theDog</code>, ovvero un oggetto di tipo <code>Dog</code>:</p> - -<pre class="brush: js notranslate">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'); -</pre> - -<p>Richiamando il metodo <code>toString()</code> su questo oggetto personalizzato, esso restituisce il valore di default ereditato da {{jsxref("Global_Objects/Object", "Object")}}:</p> - -<pre class="brush: js notranslate">theDog.toString(); // returns [object Object] -</pre> - -<p>Il codice seguente crea e assegna il metodo <code>dogToString()</code> per sovrascrivere il metodo di default <code>toString()</code>. Questa funzione genera una stringa contenente i valori name, breed, color e sex dell'oggetto, nella forma di "<code>property = value;</code>".</p> - -<pre class="brush: js notranslate">Dog.prototype.toString = function dogToString() { - var ret = 'Dog ' + this.name + ' is a ' + this.sex + ' ' + this.color + ' ' + this.breed; - return ret; -} -</pre> - -<p>Col precedente codice, la funzione <code>dogToString()</code> è richiamata automaticamente da JavaScript ogni volta che l'oggetto <code style="font-style: normal;">theDog</code> è usato in un contesto string, e restituisce la seguente stringa:</p> - -<pre class="notranslate">Dog Gabby is a female chocolate Lab -</pre> - -<h3 id="Example_Using_toString_to_detect_object_type" name="Example:_Using_toString_to_detect_object_type">Esempio: Uso di <code>toString()</code> per individuare l'oggetto class</h3> - -<p><code>toString()</code> può essere usato con ogni oggetto e permette di ottenere il suo class. Per usare <code>Object.prototype.toString()</code> 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 <code>thisArg</code>.</p> - -<pre class="brush: js notranslate">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] -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifiche</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>ECMAScript 1 Edizione.</td> - <td>Standard</td> - <td>Definizione iniziale. Implementato in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2.4.2', 'Object.prototype.toString')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Richiamato su {{jsxref("Global_Objects/null", "null")}} restituisce <code>[object <em>Null</em>]</code>, e {{jsxref("Global_Objects/undefined", "undefined")}} restituisce <code>[object <em>Undefined</em>]</code></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object.prototype.tostring', 'Object.prototype.toString')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_browser">Compatibilità browser</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Caratteristiche</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Support Base</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Support Base</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also" name="See_also">Vedi anche</h2> - -<ul> - <li>{{jsxref("Object.prototype.toSource()")}}</li> - <li>{{jsxref("Object.prototype.valueOf()")}}</li> -</ul> |