Thank you all for "trying to understand me" and helping me, I know I haven't
explained myself very well đ. Surely the implementation of my templates
(Controllers and Models) is not the most correct.
I'll try to explain myself better...
I have several types of use of the " ... args" parameters:
1.- Methods/Functions in base class that are overridden in child classes and
may or may not have fixed parameters, and a final parameter "... args":
1.1.- protected function fn_TypeA( ... args):void { }
override protected function fn_TypeA( ... args):void {
super.fn_TypeA.apply(this, args); // As Josh commented.
}
1.2.- protected function fn_TypeB(par1:int, par2:string, ... args):void
{ }
override protected function fn_TypeB(par1:int, par2:string, ...
args):void {
super.fn_TypeB.apply(this, [par1, par2].concat(args));
// As Greg commented, I haven't been able to test this yet, but I'm sure it's
correct đ
}
2.- Methods/Functions within a class, which may or may not override the base
class: (I show a real example)
In the base class I have these functions:
public function itemFilterDefault(... args):ICTypeArqParams {
// I can't implement it like this because I get an error
"retriveNewItemFilterDefault is not a function"
// var item:ICTypeArqParams =
retriveNewItemFilterDefault.apply(this,args);
var item:ICTypeArqParams = retriveNewItemFilterDefault(args);
if (pagination) {
item.pageSize = pageSize;
item.pageIndex = -1;
}else{
item.pageSize = -99;
item.pageIndex = -99;
}
return item;
}
public function retriveNewItemFilterDefault(... args):ICTypeArqParams{
return null; } // This function is the one that will normally be overridden in
child classes
2.1.- In a daughter class I have:
override public function itemFilterDefault(... args):ICTypeArqParams {
return super.itemFilterDefault.apply(this,args) as
CTypeParSegUserNet;
}
override public function retriveNewItemFilterDefault(...
args):ICTypeArqParams
{
return new CTypeParSegUserNet(args);
}
2.2.- In another daughter class I could have:
override public function itemFilterDefault(... args):ICTypeArqParams {
return super.itemFilterDefault.apply(this,args) as
CTypeParSegUserNet;
}
override public function retriveNewItemFilterDefault(...
args):ICTypeArqParams
{
var it:CTypeParSegUserNet = getSpecialitem("typeA", args); // I
can't use apply because I get an error "it's not a function"
return it;
}
private function getSpecialitem(type:String, ...
args):CTypeParSegUserNet
{
var it:CTypeParSegUserNet = new CTypeParSegUserNet(args);
if( type == "typeA")
It.level = 5;
else
It.level = 1;
return it;
}
I hope I have been clearer with these examples.
Thank you very much for your attention and help.
Hiedra
-----Mensaje original-----
De: Greg Dove <[email protected]>
Enviado el: domingo, 1 de diciembre de 2024 21:03
Para: [email protected]
Asunto: Re: Parameters of type paramArray
Not knowing exactly what the method signature for 'fn_hello' is makes it a
little uncertain to advise, but it seems like you might want this
super.fn_hello.apply(this,[index].concat(args))
instead of
super.fn_hello.apply(index,[this].concat(args))
On Mon, Dec 2, 2024 at 7:00âŻAM Harbs <[email protected]> wrote:
> Iâm not clear on what youâre trying to do.
>
> Given a variable of an array arr = [1,2,3]:
>
> If you call the function directly (i.e. fn_fooBisarr)), the full array
> will be the first argument of the function, so youâll get
> fn_fooBis([1,2,3]); If you call the function using.
> fn_fooBis.apply(thisArg,arr), thatâs the same as calling:
> fn_fooBis(1,2,3) (thisArg can be the this context you want or null if
> you donât care about the âthis" context)
>
> Harbs
>
> > On Dec 1, 2024, at 4:56 PM, Maria Jose Esteve <[email protected]> wrote:
> >
> > When I have to pass the "args" to a function without super, it
> > doesn't
> allow me to use .apply(this,args) in all cases and if I pass them
> directly the recursive increment occurs again...
> Aaaaaaaaaaaaaaahhhhhhhhhhhhh
> >
> > I've looked at the SDK code and it's not clear to me how I can do it.
> > For example:
> > protected function fn_foo( ... args){
> > // fn_fooBis.apply(this, args) // not working
> > fn_fooBis(args);
> > }
> > Private function fn_fooBis(... args):void{
> > trace( args); // two nestings.
> > }
> >
> > Hiedra
> >
> > -----Mensaje original-----
> > De: Maria Jose Esteve <[email protected]> Enviado el: domingo, 1 de
> > diciembre de 2024 15:12
> > Para: [email protected]
> > Asunto: RE: Parameters of type paramArray
> >
> > Perfect Josh, thanks.
> >
> > When the paramArray is, for example, the second parameter, what
> > would
> that look like?
> > For example:
> > override protected function fn_hello(index:int, ... args){
> > // These are the tests I have done but none of them work for me
> > super.fn_hello.apply(index,args);
> > super.fn_hello.apply(index,[this].concat(args)); // Add "this"
> and, for example, index 0 is not the first parameter of args but
> "this" (as expected)} ,,,
> >
> > Hiedra
> >
> > -----Mensaje original-----
> > De: Josh Tynjala <[email protected]> Enviado el: viernes, 29
> > de
> noviembre de 2024 18:14
> > Para: [email protected]
> > Asunto: Re: Parameters of type paramArray
> >
> > I think that this should do what you want:
> >
> > super.reevalAccesControl.apply(this, args);
> >
> >
> > --
> > Josh Tynjala
> > Bowler Hat LLC <https://bowlerhat.dev>
> >
> >
> > On Thu, Nov 28, 2024 at 7:26âŻAM Maria Jose Esteve
> > <[email protected]>
> wrote:
> >
> >> Hi, I've always faced this problem, but I don't know how to give a
> >> definitive solution.
> >> Parameters of type paramarray increase their nesting from one call
> >> to another, for example:
> >>
> >> Public class ControllerFirst extends ControllerBase {
> >> ...
> >> private function fnmove():void{
> >> var foo:String = "hello";
> >> reevalAccessControl(foo);
> >> }
> >> ...
> >> override protected function reevalAccessControl(... args):void{
> >> // In the first call, from fnmove "arguments" you
> >> have an element [0] with a value "hello"
> >> super.reevalAccesControl(args);
> >> ...
> >> }
> >> }
> >>
> >> Public class ControllerBase
> >> {
> >> ...
> >> protected function reevalAccessControl(... args):void{
> >> // When this function is called from ControllerFirst
> >> arguments has an element [0] but this element in turn is an array
> >> of 1 element and the value "hello" is found in args[0][0] on a second level
> >> ...
> >> }
> >> ...
> >> }
> >>
> >> I don't know if I have explained myself... I understand why it
> >> happens but I wonder if there is a way to pass this type of
> >> arguments so that the nesting level 0 is respected and a level is not
> >> added for each call.
> >>
> >> Thx.
> >> Hiedra
> >>
> >>
>
>