You have two options for a solution here:

1) remove that child before you call setOptions:

if (options.child) {
  this.child = options.child;
  delete options.child;
}

2) make the child option a function that returns one:

if (this.options.child) this.child = this.options.child();

//usage
new A({ child: Function.from(B) });




On Fri, Nov 19, 2010 at 9:44 AM, אריה גלזר <[email protected]> wrote:

> if i understand correctly, the real issue is if child requires other
> parameters.
> and anyway, a class creating other classes (other than perhaps mootools
> utilities) is a bad habit.
> imo, if the class is supplied via options, the supplier should already
> instantiate the class
>
>
> On Fri, Nov 19, 2010 at 7:21 PM, Alex K <[email protected]> wrote:
>
>> I apologize for bringing up a topic that might have been discussed in the
>> past, but I wonder if anyone has a definite and clear solution to this
>> problem:
>>
>>
>> var A = new Class({
>>   Implements : Options,
>>
>>   initialize : function(options) {
>>       this.setOptions(options);
>>       if (options && typeOf(options.child) == 'class')
>>           this.child = new options.child(options);
>>   }
>> });
>>
>> var B = new Class({
>>       Implements : A,
>> });
>>
>> // "Maximum call stack size exceeded"
>> var instance = new A({child : B});
>>
>>
>> Also, due to some design considerations, implementing "initialize" in
>> every subclass is not an option.
>>
>> Thanks in advance.
>> -a
>>
>
>
>
> --
> Arieh Glazer
> אריה גלזר
> 052-5348-561
> 5561
>
>

Reply via email to