Thanks! I never realized you can use the new keyword on an existing
class like that...


On Oct 28, 12:41 pm, Jan Kassens <[EMAIL PROTECTED]> wrote:
> I'd pass an actual class to registerType instead of a string, than you  
> could do something like (I stripped the unused stuff):
>
> (in case the inline code didn't 
> work:http://pastie.textmate.org/private/8sirah0pp7xvgtbtas1eq
>   )
>
> Sgd.Ui.Factory = new Class({
>
>      initialize: function(){
>          this.list = new Hash();
>      },
>
>      registerType: function(type, klass){
>          this.list.set(type, klass);
>      },
>
>      get: function(options){
>          if (options.type == undefined || !
> this.list.has(options.type)) return null;
>          return new this.list.get(options.type)(options);
>      }
>
> });
>
> Sgd.Ui.Factory.registerType('html', Request.HTML);
>
> Sgd.Ui.Factory.get('html', someOptions);
>
> On Oct 28, 2008, at 20:10, jonlb 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
>
> --
> twitter/blog:http://kassens.net

Reply via email to