Variable undefined dans un console.log
Bonjour, je fais appel à vous car je ne voit pas du tout d’où peu venir le problème. Dans le code ci-dessous. Ma variable this.implementation est bien renseigné. Le premier console.log() affiche bien le contenu.
Par contre dans la méthode validMethod(), je ne peux pas y accéder.
le console.log me retourne undefined
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
function Interface(implementation){
this.implementation = implementation;
console.log(this.implementation);
}
Interface.prototype.constructor = Interface;
Interface.prototype.validMethodCount = function(){
return this.length !== this.implementation.length
};
Interface.prototype.validMethod = function(){
for(var i in this){
console.log(this.implementation);
if(i !== "validMethodCount" && i !== "validMethod "){
if(this.implementation[i] == undefined){
throw "Method " + i + " is missing. You must implement it;";
}
}
}
}; |
Quelqu'un saurait me dire pourquoi?
Seconde question, en utilisant le même structure( prototype) est-il possible d'utiliser des accesseurs pour les variables de classe? en passant les variables comme implementation en
Code:
var implementation;
au lien de
Code:
this.implementation
merci d'avance.