[POO] instanceof et exploration d'un objet
Bonjour à tous... Voici le script qui essaye l'opérateur instanceof :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function A() {
this.x = 0;
this.y = '222';
this.objDate = new Date();
this.objB = new B();
}
function B() {
this.bb = 99;
}
function dumpObj( obj )
{
alert( "dans la fct obj == objet ? " + (obj instanceof Object) );
for ( att in obj ) alert( att + " == objet ? " + (att instanceof Object) )
}
function testJSDebug()
{
var obj = new A();
alert( "avant appel obj == objet ? " + (obj instanceof Object) );
dumpObj( obj );
} |
En sortie :
Citation:
avant appel obj == objet ? true
dans la fct obj == objet ? true
x == objet ? false
y == objet ? false
objDate == objet ? false
objB == objet ? false
8O En somme, il reconnait l'objet quand on le lui passe tel quel, mais pas quand il est pris comme attribut ?????? 8O
Ou bien (plus probablement...) j'ai raté un éléphant ?