J'ai le code JavaScript suivant:JavaScript littéral d'objet et tableau
oCoord = {x: null, y: null};
var aStack = [];
oCoord.x = 726;
oCoord.y = 52;
aStack.push(oCoord);
oCoord.x = 76;
oCoord.y = 532;
aStack.push(oCoord);
oCoord.x = 716;
oCoord.y = 529;
aStack.push(oCoord);
Maintenant, cela crée la structure suivante (un tableau de trois objets). Cependant, lorsque j'essaie d'accéder aux propriétés de chaque objet, elles ressortent toutes identiques. Pourquoi est-ce?
alert(aStack[0].x); // Outputs 716
alert(aStack[1].x); // Outputs 716
alert(aStack[2].x); // Outputs 716
Qu'est-ce que je fais mal?
Snap! Battez-moi. –
merci, parfait. Réponse correcte donnée pour la première explication correcte complète – 32423hjh32423