title: Correct way to precompile Handlebars template to function, as Jade do it
body: <p>In short, what I need - to precompile programmatically (not CLI) handlebars template to browser-side function and at browser use it with <code>handlebars.runtime.js</code> in this way:</p>
  
  <pre><code>html = template_as_fn(data_object);
  </code></pre>
  
  <p>Why I need it - I work on YA ComonJS to browser packer tool, <a href="https://github.com/Meettya/clinch" rel="nofollow noreferrer">clinch</a> and I want to support Handlebars too.</p>
  
  <p>So, I looking for correct way to precompile Handlebars template to function, without <code>eval()</code> and other voodoo magic.</p>
  
  <p>Things like in this <a href="https://stackoverflow.com/questions/14129149/manually-use-precompiled-handlebars-templates?rq=1">answer</a></p>
  
  <pre><code>var data = { name: "Greg" };
  var source = "&lt;p&gt;Howdy, {{ name }}&lt;/p&gt;";
  
  eval("var templateFunction = " + Handlebars.precompile(source));
  var template = Handlebars.template(templateFunction);
  
  template(data);
  =&gt; "&lt;p&gt;Howdy, Greg&lt;/p&gt;"
  </code></pre>
  
  <p>make me sad.</p>
  
  <p>For example, with Jade I can use <a href="https://github.com/Meettya/clinch/blob/master/src/file_processor.coffee#L114" rel="nofollow noreferrer">file processor</a> in this way</p>
  
  <pre><code>'.jade'   : (data, filename, cb) -&gt;
    content = Jade.compile data, _.assign jade_settings, {filename}
    cb null, "module.exports = #{content}"
  </code></pre>
  
  <p>Is it possible to do something like Jade with Handlebars?</p>