Sweet, I got it working after that. I almost resorted to making
classes that extend the main one but this is the same functionality in
about 10 lines of code.

On Mar 15, 6:14 pm, Thomas Aylott / subtleGradient
<[email protected]> wrote:
> Make sure you're building the builder object inside your initilize  
> function so that "this" is set properly. Also you need to actually run  
> the function once you get it. So add () to the end after ].
>
> --
> Thomas Aylott / SubtleGradient (from iPhone)
>
> On Mar 15, 2009, at 7:17 PM, pradador <[email protected]> wrote:
>
>
>
>
>
> > I don't know if this is possible as I can't get it to work, so I
> > thought I'd ask here. My class has various methods that do the same
> > basic functionality in different flavors. I can't just use arguments
> > since each method is fundamentally different and needs its own code.
> > So let's say I have methods:
>
> > createWithOl: function() {},
> > createWithDiv: function() {},
> > createWithTable: function() {}
>
> > I have an option called "type" that is set to either "ol", "li", or
> > "table" depending on what the user wants. What I'm trying to do is
> > make a variable that looks like this...
>
> > builder: {
> >  ol: this.createWithOl,
> >  div: this.createWithDiv,
> >  table: this.createWithTable
> > }
>
> > ...so that I can then use something like this to build the correct
> > element (instead of using a switch statement):
>
> > toElement: function() {
> >  this.element = this.builder[this.options.type];
> > }
>
> > I've done the code but it hasn't worked so far. I'm guessing is a
> > scope related issue but I can't seem to figure out what I need to pass
> > to the functions. Any tips?

Reply via email to