Einzelnen Beitrag anzeigen
Alt 22-02-2003, 14:28   #5 (permalink)
flory
www.kruesch.de
 
Benutzerbild von flory
 
Registriert seit: Feb 2002
Beiträge: 1.057
um ehrlich zu sein, habe ich das mit den Lambdas auch
noch nicht 100%ig kapiert, ich glaube das ist noch
etwas komplizierter.

Hier nochmal dasselbe Beispiel mit flexiblen Parametern:
ActionScript:
  1. Function.prototype.after=function(g) {
  2.         var f=this;
  3.         return function() {
  4.                 return f(g(arguments));
  5.         }
  6. }
  7.  
  8. function addTag(tag,attributes) {
  9.         var stag='<'+tag+" "+attributes+'>';
  10.         var etag='</'+tag+'>';
  11.         return function(x) {
  12.                 return stag+x+etag;
  13.         }
  14. }
  15.  
  16. res=addTag("b","class=\"classname\"").after(addTag("b"))("helo");

und Schleife mal anders:

ActionScript:
  1. Function.prototype.loop=function(x) {
  2.   var f=this;
  3.   return function() {
  4.     for (var i=0; i<x; i++) {
  5.         f.apply(f,arguments);      
  6.     }
  7.   }
  8. }
  9.  
  10. a=function(x,y) {
  11.     trace(x+" "+y);
  12. }
  13.  
  14. a.loop(10)("helo","world");

Sonnige Grüsse
Florian
__________________
www.planet-xaml.net
flory ist offline   Mit Zitat antworten