Thanks you, GREAT idea :).
On Sep 28, 4:52 pm, "Nathan White" <[EMAIL PROTECTED]> wrote:
> The 'MyClass' objects that your trying to initialize, do you have control
> over the interface? From my perspective if you look at this from another
> angle all your problems go away. Instead of having your 'MyClass' accept
> multiple parameters, why not take a parameter object. Extend your class with
> 'Options' in this fashion you could put your default values in and not worry
> about testing. In addition you don't need to worry about parameter order.
>
> function initObj(params){
> var o = new MyClass(params);
>
> }
>
> MyClass = new Class({
> Implements : [Options],
>
> options : {
> 'default1' : 'value1',
> 'default2' : 'value2
> },
>
> initialize : function(params){
> this.setOptions(params);
>
> }
> });
>
> Documentation on 'Options'http://mootools.net/docs/Class/Class.Extras#Options
>
> On Sun, Sep 28, 2008 at 5:40 AM, Nir Tayeb <[EMAIL PROTECTED]> wrote:
>
> > I've got a situation in which i need to create objects with parameters
> > passed to me as Array.
> > Currently i do this, in this way:
> > ---
> > function initObj(params){ // params is Array
> > var o = $merge({}, new MyClass());
> > o.initialize.run(params, o);
> > }
> > ---
> > This solution has one issue, it required me to check for empty
> > arguments list in the constructor.
>
> > ---
> > initialize: function(p1, p2, p2){
> > if (arguments.length == 0) {
> > return;
> > }
> > // the rest of the code
> > }
> > ---
>
> > There is a better way to do this?
>
> > Thanks, Nir.