title: Composing complex code as string in javascript
body: <p>I'm designing custom <code>Blockly</code> blocks with their own JavaScript code, when the code I'm trying to output as string is a one liner, that's not so complicated but when the code I'm trying to associate to my custom block, doing it by concatenation of variables, single, double quotes it starts being messy and produces code with syntax errors that is hard to troubleshoot.</p>
  
  <p>Here's code for a simple block, the way I do it now:</p>
  
  <pre><code>this.EnableAllItems = function (block) {
      var target_field = block.getField('target_field');
      var code = "$('#" + target_field.getText() + " option').removeAttr('disabled');\r\n";
      return code;
  }
  </code></pre>
  
  <p>This is a block I use to enable all <code>options</code> in a <code>select</code> input.</p>
  
  <p>Works for simple code. But what I'd like to be able to do is compose the JS code literally and have it converted to string later on.</p>
  
  <p>Would something like this be possible:</p>
  
  <pre><code>function enableItemsLogic(targetField) {
      $('#' + targetField + ' option').removeAttr('disabled'); 
  } 
  
  this.EnableAllItems = function (block) {
      var target_field = block.getField('target_field');
      //somehow return the above function as code with the literal parameter filled in ?
      var code = enableItemsLogic(target_field.getText());
      return code;
  }
  </code></pre>
  
  <p>Are there any JS tricks that would allow me to do that? </p>