HighDots Forums  

jquery events binding

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss jquery events binding in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
ZER0
 
Posts: n/a

Default Re: jquery events binding - 10-06-2009 , 02:53 PM






On 10/6/09 6:30 PM, Z. wrote:

Quote:
il mio array è associativo,

In JS non esistono "Array Associativi".
Esistono Array ed esistono Object usati a mo' di Hashtable; ma nulla
di più.

Quindi se pensi di usare un "Array Associativo" abbiamo un problema.


eh fosse uno solo... si che saremmo a cavallo

Un array popolato solo a forza di push è un'array normale con indice
numerico giusto?
Come ti ho detto non esistono "array associativi" in JS, e non c'è
altro modo di popolare un Array se non tramite indice numerico. Che
tu lo faccia col push, o in altro modo, non si sfugge.
Se tu pensi che hai un array associativo semplicemente perché in JS
una sintassi del genere è lecita:

var myArray = new Array();

myArray["mykey"] = "a value";

Chiediti come mai:

alert(myArray.length);

Ti risponde 0 invece di 1.

Non hai aggiunto un elemento all'array.
Hai semplicemente aggiunto dinamicamente una proprietà all'istanza:

alert(myArray.mykey) // "a value"

Dato che in JS si può accedere alle proprietà di un oggetto tramite
due diverse notazioni, ovvero: "dot notation", e la "square bracket
notation". Ad esempio:

alert(myArray.length);

essendo "alert", un "metodo" (proprietà con riferimento a funzione)
di "window", usando la dot notation potrebbe esser scritto così:

window.alert(myArray.length);

Mentre con la square bracket notation:

window["alert"](myArray.length);

È proprio grazie alla "square bracket notation", che spesso vengono
usati gli Object a mo' di Hashtable:

var myHashtable = {}; // è equivalente a new Object()
myHashtable["mykey"] = "a value";
myHashtable["yourkey"] = "another value";

for (var key in myHashtable)
alert(key + " : " + myHashtable[key]);

Questo è un esempio semplicistico, giusto a scopo esemplificativo.

--
"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth."

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.