0

I have a bunch of these in a module separate from my execution code:

const warnings = {
  functionDoesNotReturnValue: {
    message: `${name} did not return a value`,
    get: (name) => {
      return {
        action: warnings.functionDoesNotReturnValue.action,
        message: `'${name}' did not return a value`,
      };
    },
  },

I currently have the get method added, which just provides the interpolation string required and applies it to a copy of message within the function.

But I would like to remove the redundant get function entirely and supply the provided name parameter directly to the message property as required, since every warning currently needs its own redundant get method, which simply contains copy of the message property and returns the interpolated version, purely so that execution of the string template may be deferred until the time get is run.

I can't figure out how to do this via tag methods: whatever happens, the template string appears to evaluate the as soon as the program is run. Any suggestions on a more elegant way to handle this?

sdgluck
  • 24,894
  • 8
  • 75
  • 90
brokenalarms
  • 305
  • 3
  • 9
  • The `message` property is just a string, the template literal has already been evaluated at that point. If you want to delay processing, that's what functions are for. Why do you have the `message` property at all? It doesn't seem to do anything in this context. Why not have `functionDoesNotReturnValue` be a function? – loganfsmyth Sep 11 '15 at 04:59
  • Well yes, the message property is an exact duplicate of the get method at present - I am currently using the `get` method, and not the `message` property at all. I was just showing both simultaneously to indicate that `get` was what I was currently using, but `message` was how I wanted it to be via a tag function or something. The suggested answer does answer my question - in a word, no, I can't make a reusable template literal. Apologies, I spent some time looking but couldn't find that accepted answer. – brokenalarms Sep 12 '15 at 04:12

0 Answers0