0
Ich versuche, eine Funktion, die in einer anderen "Klasse" erstellt wird, und ich möchte es in der socket.on (...) verwenden, aber es funktioniert nicht, es zeigt weiterhinFunktionsaufruf in Knoten js mit Socket
this.function ist keine Funktion.
hier ist der Code
//calling the function
Serveur.prototype.traitementSurConnection = function(socket) {
var that = this
socket.on('connection', function (creator, typeArtifact,idConteneur, typeConteneur) {
that.addArtifact('momo', 'img', 1,0);
})
};
//the function
ZoneCollaborative.prototype.addArtifact = function(creator, typeArtifact,idConteneur, typeConteneur) {
// calcul d'un nouvel identifiant
var id = this.setIdAr();
console.log(' *** ZC : calcul nouveau IdArtifact = '+id);
// création de l'artifact
var monArtifact = new Artifact(id, creator, typeArtifact, idConteneur,
typeConteneur);
console.log(' *** ZC : creation artifact'+monArtifact.getId());
// ajout à la liste
this.artifacts.push(monArtifact);
console.log(' *** ZC : total artifact ='+ this.artifacts.length);
};
Post mehr Code für Serveu r Erstellung und Verwendung von Instanzen – dfsq
Teilen 'Serveur' und' ZoneCollaborative' den Prototyp? Können Sie den Code dort posten, wo dies geschieht? –
nein sie teilen es nicht –