Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2930 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [JS] probleme pr instancier une objet

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[JS] probleme pr instancier une objet

n°1362249
ham_mer
Posté le 09-05-2006 à 11:49:57  profilanswer
 

Voila, je travaille avec le framework Dojo pour AJAX et j'aimerais instancier un objet de type Reflex qui permet de récupérer toutes les propriétés d'une classe de dojo.
 
Seulement je n'arrive pas a me servir de cette classe.
Il est marqué en commentaire qu'elle ne peut etre instanciée :
 
//Static object that can activate instances of the passed type.
 
alors j'essaye de faire comme ceci :
 
dojo.reflect.Reflector.getPropertiesFromType ('FloatingPane');
Pour récupérer les propriétés d'un panel flotant mais ça ne marche pas :(
 
 
Voici le code de la classe :
 

Code :
  1. dojo.reflect.Reflector = new (function(){
  2. this.getTypeFromString = function(s) {
  3.  var parts = s.split("." ), i = 0, obj = dj_global ;
  4.  do { obj = obj[parts[i++]] ; } while (i < parts.length && obj) ;
  5.  return (obj != dj_global) ? obj : null ;
  6. };
  7. this.typeExists = function(s) {
  8.  var parts = s.split("." ), i = 0, obj = dj_global ;
  9.  do { obj = obj[parts[i++]] ; } while (i < parts.length && obj) ;
  10.  return (obj && obj != dj_global) ;
  11. };
  12. this.getFieldsFromType = function(s) {
  13.  var type = s ;
  14.  if (typeof(s) == "string" ) {
  15.   type = this.getTypeFromString(s) ;
  16.  }
  17.  var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
  18.  return this.getFields(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
  19. };
  20. this.getPropertiesFromType = function(s) {
  21.  var type = s ;
  22.  if (typeof(s) == "string" ) {
  23.   type = this.getTypeFromString(s);
  24.  }
  25.  var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
  26.  return this.getProperties(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
  27. };
  28. this.getMethodsFromType = function(s) {
  29.  var type = s ;
  30.  if (typeof(s) == "string" ) {
  31.   type = this.getTypeFromString(s) ;
  32.  }
  33.  var nullArgs = (new dojo.reflect.MethodInfo(type)).getNullArgumentsObject() ;
  34.  return this.getMethods(dojo.reflect.Activator.createInstance(s, nullArgs)) ;
  35. };
  36. this.getType = function(o) { return o.constructor ; } ;
  37. this.getFields = function(obj) {
  38.  var arr = [] ;
  39.  for (var p in obj) {
  40.   if(this.getType(obj[p]) != Function){
  41.    arr.push(new dojo.reflect.PropertyInfo(p, this.getType(obj[p]))) ;
  42.   }else{
  43.    arr.push(new dojo.reflect.MethodInfo(p, obj[p]));
  44.   }
  45.  }
  46.  return arr ;
  47. };
  48. this.getProperties = function(obj) {
  49.  var arr = [] ;
  50.  var fi = this.getFields(obj) ;
  51.  for (var i = 0; i < fi.length; i++){
  52.   if (this.isInstanceOf(fi[i], dojo.reflect.PropertyInfo)){
  53.    arr.push(fi[i]) ;
  54.   }
  55.  }
  56.  return arr ;
  57. };
  58. this.getMethods = function(obj) {
  59.  var arr = [] ;
  60.  var fi = this.getFields(obj) ;
  61.  for (var i = 0; i < fi.length; i++){
  62.   if (this.isInstanceOf(fi[i], dojo.reflect.MethodInfo)){
  63.    arr.push(fi[i]) ;
  64.   }
  65.  }
  66.  return arr ;
  67. };
  68. /*
  69. this.implements = function(o, type) {
  70.  if (this.isSubTypeOf(o, type)) return false ;
  71.  var f = this.getFieldsFromType(type) ;
  72.  for (var i = 0; i < f.length; i++) {
  73.   if (typeof(o[(f[i].name)]) == "undefined" ){
  74.    return false;
  75.   }
  76.  }
  77.  return true ;
  78. };
  79. */
  80. this.getBaseClass = function(o) {
  81.  if (o.getType().prototype.prototype.constructor){
  82.   return (o.getType()).prototype.prototype.constructor ;
  83.  }
  84.  return Object ;
  85. } ;
  86. this.isInstanceOf = function(o, type) {
  87.  return (this.getType(o) == type) ;
  88. };
  89. this.isSubTypeOf = function(o, type) {
  90.  return (o instanceof type) ;
  91. };
  92. this.isBaseTypeOf = function(o, type) {
  93.  return (type instanceof o);
  94. };
  95. })();


 

mood
Publicité
Posté le 09-05-2006 à 11:49:57  profilanswer
 

n°1362654
ham_mer
Posté le 09-05-2006 à 17:50:59  profilanswer
 

dojo.reflect.Reflector = new (function(){...
 
Apparement ce n'est pas comme ça qu'on déclare on classe, mais je n'arrive pas à trouver ce que représent cette synthaxe...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [JS] probleme pr instancier une objet

 

Sujets relatifs
probleme : Select d'une requette MYSQLORACLE 9i : problème ISO 2
Probleme avec les caractères accentués en ut-8(sql)problème d'affichage avec preg_match
quelle différence entre Attribut et Property (concernant un objet)?Probleme affiche de mon site sous FireFox
problème de bouton...Problème pour envoyer un mail (JavaMail)
Problème avec les packages...(PASCAL) Rotation d'un volume, big probleme!!!
Plus de sujets relatifs à : [JS] probleme pr instancier une objet


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR