title: JavaScript dynamic formatting
body: <p>I've been playing with JavaScript dynamic formatting today and I can't seem to get this to work and wondered if anyone out there has done the same.</p>
  
  <p>This is my function I've created to pass in a set number of formatters in for, say, strings, numbers etc:</p>
  
  <pre><code>function Formatter(formatters) {
              this.format = function(value, type) {
                  switch(type) {
                      case "string":
                          return value =&gt; formatters.string
                          break;
                       case "currency":
                          return value =&gt; formatters.curency
                          break;
                       case "number":
                          return value =&gt; formatters.number
                          break;
                      default: 
                          return value;
                          break;
                  }
              }
          }
  </code></pre>
  
  <p>I'm sending to it in the initialisation this:</p>
  
  <pre><code>formatters: {
                          'string': input =&gt; input,
                          'number': input =&gt; input.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'),
                          'currency': input =&gt; input.toFixed(3),
                          'url': input =&gt; (`&lt;a href="${input.url}"&gt;${input.title}&lt;/a&gt;`)
                      }
  </code></pre>
  
  <p>Soo...</p>
  
  <pre><code>var formatter = new Formatter({
                              'string': input =&gt; input,
                              'number': input =&gt; input.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'),
                              'currency': input =&gt; input.toFixed(3),
                              'url': input =&gt; (`&lt;a href="${input.url}"&gt;${input.title}&lt;/a&gt;`)
                          });
  
  // This should display "test" as the format is just itself.
  formatter.format("test", "string);
  </code></pre>
  
  <p>What it actually displays is <strong>value => formatters.string</strong>.</p>
  
  <p>Is there any way to achieve what I'm trying to do here?</p>