Alternative to fat arrow function for precompile

Viewed 50

I have some javascript written for an input mask in rails 4. The input mask works fine on the development side but fails to precompile on the server with the following error:

ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (>) (line: 6, col: 33, pos: 222)

I've tried reformatting the function a number of ways but nothing but the fat arrow => seems to let my input mask work.

const mask = originalTemplate => (function() {
    let template = originalTemplate;
    const input = $(this).val().replace(/[^0-9]/g, '');
    for (let x = 0, end = input.length, asc = 0 <= end; asc ? x < end : x > end; asc ? x++ : x--) {
      template = template.replace('x', input[x]);
    }
    if (input.length === 0) { template = ''; }
    let index = template.indexOf('x');
    while ((index > 0) && !(numbers.indexOf(template[index-1]) >= 0)) {
      index = index - 1;
    }
    if (index < 0) { index = template.length; }
    return $(this).val(template.substring(0, index));
  });

Is there a way to write this that will accomplish the same thing but without using a =>?

0 Answers
Related