11563 sujets

JavaScript, DOM et API Web HTML5

Bonjour à tous.
J'ai un objet défini de la façon suivante :

var UPDATEBOX = {
	perform: function(event) {
		event.stopPropagation();
		this.close();
		if(this.textField.isChanged()) {
			this.noteInfo.update(this.textField.getValue());
		}
	},
	close: function(event = '') {
		if(event) event.stopPropagation();
		document.body.appendChild(this.updateBox);
	},
	init: function(noteInfo, noteAction) {
		this.updateBox = $('UPDATEBOX');
		if(!this.updateBox) {
			this.titleNode = newNode('h3', '.closeable');
			this.titleNode.addEventListener('click', event => this.close(event));
			this.textField = new InputField('', '', 'textarea');
			this.updateButton = new ButtonField('update', 'Enregistrer', this.perform.bind(this));
			this.updateSet = new Fieldset('', '#UPDATEBOX', this.titleNode, this.textField, this.updateButton);
			this.updateBox = this.updateSet.node();
			this.close();
		}
		this.noteInfo = noteInfo;
		this.noteAction = noteAction;
		this.titleNode.innerText = noteInfo.title;
		this.textField.reset(noteInfo.text);
		Deactivate();
		this.noteInfo.element.appendChild(this.updateBox);
	}
}

Au moment de l'exécution le programme déclare que this.perform est inconnu.

Après pas mal d'essais j'ai ajouté en tête une déclaration de propriété bidon

var UPDATEBOX = {
	name: 'UPDATEBOX',
	perform: function(event) {
		event.stopPropagation();
		this.close();
		if(this.textField.isChanged()) {
			this.noteInfo.update(this.textField.getValue());
		}
	},
       ............

et l'erreur ne se produit plus.
C'est comme si un objet devait avoir au moins une propriété et pas seulement des méthodes.
Cela vous semble-t-il normal ?
Modifié par PapyJP (24 Oct 2025 - 10:46)