title: Legitimate uses of the Function constructor
body: <p>As repeatedly said, it is considered bad practice to use the <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions#The_Function_constructor" rel="noreferrer">Function constructor</a> (also see the <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" rel="noreferrer">ECMAScript Language Specification</a>, 5<sup>th</sup> edition, § 15.3.2.1):</p>
  
  <pre><code>new Function ([arg1[, arg2[, … argN]],] functionBody)
  </code></pre>
  
  <p>(where all arguments are strings containing argument names and the last (or only) string contains the function body).</p>
  
  <p>To recapitulate, it is said to be slow, as explained by <a href="http://dev.opera.com/articles/view/efficient-javascript/?page=2#avoideval" rel="noreferrer">the Opera team</a>:</p>
  
  <blockquote>
    <p>Each time […] the <code>Function</code>
    constructor is called on a string
    representing source code, the script
    engine must start the machinery that
    converts the source code to executable
    code. This is usually expensive for
    performance – easily a hundred times
    more expensive than a simple function
    call, for example. (Mark ‘Tarquin’ Wilton-Jones)</p>
  </blockquote>
  
  <p>Though it's not <em>that</em> bad, according to <a href="https://developer.mozilla.org/Talk:En/Core_JavaScript_1.5_Reference/Functions_and_function_scope#new_Function%28%29_vs_function%28%29.7b.7d" rel="noreferrer">this post</a> on MDC (I didn't test this myself using the current version of Firefox, though).</p>
  
  <p>Crockford <a href="http://javascript.crockford.com/survey.html" rel="noreferrer">adds</a> that</p>
  
  <blockquote>
    <p>[t]he quoting conventions of the
    language make it very difficult to
    correctly express a function body as a
    string. In the string form, early
    error checking cannot be done. […] And
    it is wasteful of memory because each
    function requires its own independent
    implementation.</p>
  </blockquote>
  
  <p>Another difference is that</p>
  
  <blockquote>
    <p>a function defined by a Function
    constructor does not inherit any scope
    other than the global scope (which all
    functions inherit). (<a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions#Function_constructor_vs._function_declaration_vs._function_expression" rel="noreferrer">MDC</a>)</p>
  </blockquote>
  
  <p>Apart from this, you have to be attentive to avoid injection of malicious code, when you create a <code>new Function</code> using dynamic contents.</p>
  
  <p>That said, T.J. Crowder says in <a href="https://stackoverflow.com/questions/3024584/improve-javascript-prototypal-inheritance/3024655#3024655">an answer</a> that </p>
  
  <blockquote>
    <p>[t]here's almost never any need for
    the similar […] new Function(...),
    either, again except for some advanced
    edge cases.</p>
  </blockquote>
  
  <p>So, now I am wondering: what are these “advanced edge cases”? <strong>Are there legitimate uses of the Function constructor?</strong></p>