Thema: traceMessages
Einzelnen Beitrag anzeigen
Alt 02-04-2003, 18:47   #2 (permalink)
bokel
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Hi Holger,
coole Idee,
da spart man sich doch einen Haufen Schreibarbeit.

Hier ist noch eine etwas andere Version,
die die jeweils zuletzt zugwiesene Methode traced.
Dann kann man selektieren, was man tracen will und was nicht, ohne dass man den Namen angeben muss.

ActionScript:
  1. traceLastMessages = function (obj) {
  2.     for (var p in obj) {
  3.         if (typeof obj[p] != 'function') {
  4.         } else {
  5.             var tmp = obj[p];
  6.             obj[p] = function () { trace('call-of> ' + arguments.callee.__methodName);arguments.callee.__originalMethod.apply(this, arguments);};
  7.             obj[p].__methodName = p;
  8.             obj[p].__originalMethod = tmp;
  9.         }
  10.         return;
  11.     }
  12. };
  13.  
  14. // Test:
  15. Kaefer = function () {
  16. };
  17. Kaefer.prototype.init = function(pStrName, pIntAge) {
  18.     this.strName = pStrName;
  19.     this.intAge = pIntAge;
  20. };
  21. traceLastMessages(Kaefer.prototype);
  22.  
  23. Kaefer.prototype.traceProperties = function() {
  24.     trace(this.strName + '(' + this.intAge + ')');
  25. };
  26.  
  27. traceLastMessages(Kaefer.prototype);
  28.  
  29. objPaule = new Kaefer();
  30. // <--
  31. objPaule.init('Paule', '23');
  32. objPaule.traceProperties();
  33. // Output:
  34. //
  35. // call-of> init
  36. // call-of> traceProperties
  37. // Paule(23)
  38.  

Vielen Dank für die gute Idee,
mfg r.
bokel ist offline   Mit Zitat antworten