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