I was taking a look recently at the Proxy class created by Joey Lott of Person13 for educational purposes, as I have just started learning OOP, and a couple questions popped into my mind.

Here is the full class:

class ascb.util.Proxy {

public static function create(oTarget:Object, fFunction:Function):Function {

   var aParameters:Array = new Array();

   for(var i:Number = 2; i < arguments.length; i++) {
     aParameters[i - 2] = arguments[i];
   }

   var fProxy:Function = function():Void {

     var aActualParameters:Array = arguments.concat(aParameters);
     fFunction.apply(oTarget, aActualParameters);

   };

   return fProxy;

 }

}

First of all, when populating aParameters, why couldn't you just do:

aParameters = arguments.slice(2);

That seems a lot more clean and improves readability a bit, no?

Second, why exactly do you need to concat the arguments of fProxy and aParameters? I can see what it's doing; it's tacking on the additional arguments supplied to Proxy.create onto the arguments of the fProxy function (which is then returned) -- but I can't really envision a situation where that would be needed? For instance:

class someClass {

   private var _someMc:MovieClip;

   function someClass(mc:MovieClip){

       _someMc = mc;

       _someMc.onRelease = Proxy.create(this,someMethod,1,2,3);

   }

   private function someMethod(a,b,c){

          trace(a+" "+b+" "+c);

   }

}

In what case would I be calling someMethod() via Proxy and supplying a set of arguments that do not match the syntax of someMethod()? It seems to me that you could just replace the following:

var aActualParameters:Array = arguments.concat(aParameters);
fFunction.apply(oTarget, aActualParameters);

with:

fFunction.apply(oTarget, aParameters);

Any clarification or insight is greatly appreciated.

Joseph Sorensen
aerosdesign.com/jsorensen
jsorensen[at]aerosdesign.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to