Objet Encapsulation Collision
Bonjour,
Voila, j'ai un petit problème de "collision" sur le code suivant. Au lieu d'afficher successivement 'Chapitre 1' puis 'Chapitre 2', cela affiche 'Chapitre 2' et 'Chapitre 2'.
Code:
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
| var oO = (function() {
var target = 'section'
var value = ''
function execute() {
targetNode.appendChild(document.createTextNode(value));
}
function addEvent(elem, type, func) {
return elem.addEventListener?
elem.addEventListener(type, func, false):
elem.attachEvent?
elem.attachEvent('on'+type, func):
elem['on'+type] = func;
}
return {
init:
function(string) {
value = string;
targetNode = document.getElementById(target);
if (targetNode) {
addEvent(window, 'load', function() {
execute();
});
}
}
}
}) ();
oO.init('Chapitre 1');
oO.init('Chapitre 2'); |
Si ce code parait disproportionné pour afficher 2 lignes dans le corps de la page, c'est une simplification d'un code plus vaste pour en comprendre l'origine du problème.
Merci par avance pour votre aide.