aboutsummaryrefslogtreecommitdiff
path: root/files/it/conflicting/web/javascript/reference/global_objects/object/index.html
blob: 568165d0be9d2b9d4d8f9a942282b1ffcf9aed4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
---
title: Object.prototype
slug: Web/JavaScript/Reference/Global_Objects/Object/prototype
translation_of: Web/JavaScript/Reference/Global_Objects/Object
translation_of_original: Web/JavaScript/Reference/Global_Objects/Object/prototype
---
<div>{{JSRef("Global_Objects", "Object")}}</div>

<h2 id="Summary" name="Summary">Sommario</h2>

<p>La proprietà <strong><code>Object.prototype</code></strong> rappresenta l'oggetto prototipo di {{jsxref("Global_Objects/Object", "Object")}}.</p>

<p>{{js_property_attributes(0, 0, 0)}}</p>

<h2 id="Description" name="Description">Descrizione</h2>

<p>In JavaScript, tutti gli oggetti sono discendenti di {{jsxref("Global_Objects/Object", "Object")}}; tutti gli oggetti ereditano metodi e proprietà di <code>Object.prototype</code> (tranne nel caso l'oggetto abbia il prototipo uguale a {{jsxref("Global_Objects/null", "null")}}, quindi creati con il metodo {{jsxref("Object.create", "Object.create(null)")}}), anche se questi possono essere sovrascritti. Per esempio, i prototipi degli altri costruttori sovrascrivono la proprietà <code>constructor</code> e forniscono un loro metodo {{jsxref("Object.prototype.toString", "toString()")}}. I cambiamenti al prototipo di Object vengono estesi a tutti gli oggetti, eccetto quelli che sovrascrivono le proprietà e i metodi cambiati.</p>

<h2 id="Properties" name="Properties">Proprietà</h2>

<dl>
 <dt>{{jsxref("Object.prototype.constructor")}}</dt>
 <dd>Specifica la funzione che ha creato l'oggetto a partire dal prototipo.</dd>
 <dt>{{jsxref("Object.prototype.__proto__")}} {{non-standard_inline}}</dt>
 <dd>È un riferimento all'oggetto usato come prototipo quando l'oggetto è stato istanziato.</dd>
 <dt>{{jsxref("Object.prototype.__noSuchMethod__")}} {{non-standard_inline}}</dt>
 <dd>Permette di definire una funzione che venga chiamata quando viene chiamato un metodo non definito.</dd>
 <dt><s class="obsoleteElement">{{jsxref("Object.prototype.__count__")}} {{obsolete_inline}}</s></dt>
 <dd><s class="obsoleteElement">Rappresenta il numero di proprietà persenti in un oggetto, ma è stato rimosso.</s></dd>
 <dt><s class="obsoleteElement">{{jsxref("Object.prototype.__parent__")}} {{obsolete_inline}}</s></dt>
 <dd><s class="obsoleteElement">Rappresenta il contesto di un oggetto, ma è stato rimosso.</s></dd>
</dl>

<h2 id="Methods" name="Methods">Metodi</h2>

<dl>
 <dt>{{jsxref("Object.prototype.__defineGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Associa una funzione a una proprietà di un oggetto. Quando si tenta di leggere il valore di tale proprietà, viene eseguita la funzione e restituito il valore che restituisce.</dd>
 <dt>{{jsxref("Object.prototype.__defineSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Associa una funzione a una proprietà di un oggetto. Quando si tenta di cambiare il valore di tale proprietà, viene eseguita la funzione.</dd>
 <dt>{{jsxref("Object.prototype.__lookupGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Restituisce la funzione definita tramite {{jsxref("Object.prototype.defineGetter", "__defineGetter__()")}}.</dd>
 <dt>{{jsxref("Object.prototype.__lookupSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
 <dd>Restituisce la funzione definita tramite {{jsxref("Object.prototype.defineSetter", "__defineSetter__()")}}.</dd>
 <dt>{{jsxref("Object.prototype.hasOwnProperty()")}}</dt>
 <dd>Determina se l'oggetto contiene direttamente una proprietà (non ereditata tramite il prototipo).</dd>
 <dt>{{jsxref("Object.prototype.isPrototypeOf()")}}</dt>
 <dd>Determina se un oggetto fa parte della catena dei prototipi dell'oggetto sul quale è richiamato questo metodo.</dd>
 <dt>{{jsxref("Object.prototype.propertyIsEnumerable()")}}</dt>
 <dd>Determina se l'<a href="/it/docs/ECMAScript_DontEnum_attribute" title="ECMAScript_DontEnum_attribute">attributo DontEnum di ECMAScript</a> interno è presente.</dd>
 <dt>{{jsxref("Object.prototype.toSource()")}} {{non-standard_inline}}</dt>
 <dd>Restituisce una stringa contenente il codice sorgente di un oggetto rappresentante l'oggetto sul quale questo metodo viene richiamato; puoi usare questo valore per creare un nuovo oggetto.</dd>
 <dt>{{jsxref("Object.prototype.toLocaleString()")}}</dt>
 <dd>Richiama {{jsxref("Object.prototype.toString", "toString()")}}.</dd>
 <dt>{{jsxref("Object.prototype.toString()")}}</dt>
 <dd>Restituisce la rappresentazione dell'oggetto sotto forma di stringa.</dd>
 <dt>{{jsxref("Object.prototype.unwatch()")}} {{non-standard_inline}}</dt>
 <dd>Termina di osservare i cambiamenti di una proprietà dell'oggetto.</dd>
 <dt>{{jsxref("Object.prototype.valueOf()")}}</dt>
 <dd>Ritorna il valore primitivo dell'oggetto.</dd>
 <dt>{{jsxref("Object.prototype.watch()")}} {{non-standard_inline}}</dt>
 <dd>Inizia a osservare i cambiamenti di una proprietà di un oggetto.</dd>
 <dt><s class="obsoleteElement">{{jsxref("Object.prototype.eval()")}} {{obsolete_inline}}</s></dt>
 <dd><s class="obsoleteElement">Esegue una stringa di codice JavaScript nel contesto dell'oggetto, ma è stato rimosso.</s></dd>
</dl>

<h2 id="Examples" name="Examples">Esempi</h2>

<p>Siccome in JavaScript gli oggetti non sono sub-classabili in modo "standard", il prototipo è una soluzione utile per creare un oggetto che funzioni da "classe di base" che contenga dei metodi comuni a più oggetti. Per esempio:</p>

<pre class="brush: js">var Persona = function() {
  this.saParlare = true;
};

Persona.prototype.saluta = function() {
  if (this.saParlare) {
    console.log('Ciao, mi chiamo ' + this.nome);
  }
};

var Dipendente = function(nome, titolo) {
  Persona.call(this);
  this.nome = nome;
  this.titolo = titolo;
};

Dipendente.prototype = Object.create(Persona.prototype);
Dipendente.prototype.constructor = Dipendente;

Dipendente.prototype.saluta = function() {
  if (this.saParlare) {
    console.log('Ciao mi chiamo ' + this.nome + ' e lavoro come ' + this.titolo);
  }
};

var Cliente = function(nome) {
  Persona.call(this);
  this.nome = nome;
};

Cliente.prototype = Object.create(Persona.prototype);
Cliente.prototype.constructor = Cliente;

var Mimo = function(nome) {
  Persona.call(this);
  this.nome = nome;
  this.saParlare = false;
};

Mimo.prototype = Object.create(Persona.prototype);
Mimo.prototype.constructor = Mimo;

var bob = new Dipendente('Bob', 'Architetto');
var joe = new Cliente('Joe');
var rg = new Dipendente('Red Green', 'Tuttofare');
var mike = new Cliente('Mike');
var mime = new Mimo('Mimo');
bob.saluta();
joe.saluta();
rg.saluta();
mike.saluta();
mime.saluta();
</pre>

<p>Stamperà:</p>

<pre>Ciao, mi chiamo Bob e lavoro come Architetto
Ciao, mi chiamo Joe
Ciao, mi chiamo Red Green, e lavoro come Tuttofare
Ciao, mi chiamo Mike</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">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.3.1', 'Object.prototype')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-object.prototype', 'Object.prototype')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">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>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>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/it/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript">Introduzione alla programmazione JavaScript orientata agli oggetti</a></li>
</ul>