Unfortunately, JavaScript has no signature-based dispatch, or
multi-clauses with pattern matching :-).
But as another option, you could use your constructor as a dispatch for
more specific setup methods. Also, rather than listing all the possible
arguments, you can just use the built-in 'arguments' array and inspect them:
construct : function() {
this.id = arguments[0];
if (arguments.length > 1)
this._construct1(arguments.slice(1));
}
This dispatch can be arbitrary complex:
construct : function() {
this.id = arguments[0];
if (typeof(arguments[1]) === 'number')
this._construct1(arguments.slice(1));
else if ((typeof(arguments[1]) === 'string') && (arguments[1] ===
'foobar'))
this._construct2(arguments.slice(1));
else if ...
this._construct3(arguments.slice(1));
...
}
T.
On 01/31/2012 01:23 PM, slah wrote:
> Hello,
> I think you can solve this case by having only one constructor (the 2nd one)
> with all possible arguments you may need.
> and then if you want to pass only one arg, this will be ok but other
> arguments will stay null.
> constructor(id, arg1, arg2, ..., argn){
> if (arg1) setProp1(arg1);
> if (arg2) setProp2(arg2);
>
> }
>
> I can call it with (id) only then arg1....argn will have null value.
>
> --
> View this message in context:
> http://qooxdoo.678.n2.nabble.com/Two-or-more-constructors-tp7219626p7239623.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel