assuming all your classes are in the global namespace (window).
obj = new window[klass]();
On Tue, Oct 28, 2008 at 3:10 PM, jonlb <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I was wondering if anyone could give me a better way to write the
> below class? I'm guessing you will be able to tell the intent from
> the code...
>
> <code>
> Sgd.Ui.Factory = new Class({
>
> Implements: [Events, Options],
>
> options:{},
>
> list: null,
>
> initialize: function(options){
> this.setOptions(options);
> this.list = new Hash();
> },
>
> registerType: function(type,klass){
> this.list.set(type,klass);
> },
>
> get: function(options){
> if ($defined(options.type) && this.list.has(options.type)) {
> klass = this.list.get(options.type);
> str = 'new '+klass+'('+JSON.encode(options)+')';
> obj = eval(str);
> return obj;
> } else {
> return null;
> }
> }
> });
>
> </code>
>
> Thanks in advance for any help!
>
> jonlb