Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] jslint and memoizer function

Expand Messages
  • Robert Sauer-Ernst
    Hi Josh, thanks. Now the difference between named function expression and function declaration seems clear (s. also http://kangax.github.com/nfe/ or
    Message 1 of 3 , May 18, 2011
    View Source
    • 0 Attachment
      Hi Josh,

      thanks. Now the difference between "named function expression" and
      "function declaration" seems clear (s. also
      http://kangax.github.com/nfe/ or
      https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope).


      Just for my curiosity @Douglas: Why do you use an example that does not
      pass JSLint? Did you add that feature later to JSLint. Or was the
      memoizer-example just to show, how JS works, but not to show, how to
      write JSLint-compatible code?

      Thx again,

      Robert from Berlin

      --- Original Nachricht ---

      Von: Joshua Bell <josh@...>
      Am: Wed, 18 May 2011 11:36:36 -0700
      Betreff: Re: [jslint] jslint and memoizer function
      An: jslint_com@yahoogroups.com
      CC:
      >
      > On Wed, May 18, 2011 at 10:37 AM, frankxberlin
      > <facebook@... <mailto:facebook%40sauer-ernst.de>>wrote:
      >
      > > Hello,
      > >
      > > in the "Good parts" and the latest talk on etsy if find as an example:
      > >
      > > var memoizer = function (memo, formula) {
      > > var recur = function (n) {
      > > var result = memo[n];
      > > if (typeof result !== 'number') {
      > > result = formula(recur, n);
      > > memo[n] = result;
      > > }
      > > return result;
      > > };
      > > return recur;
      > > };
      > >
      > > This throws an error at JSLint: "Problem at line 5 character 30: 'recur'
      > > has not been fully defined yet."
      > >
      > > How do you fix it?
      > >
      >
      > (snip)
      >
      > > Or returning a named function expression?
      > >
      >
      > That would be using the language as designed:
      >
      > ECMA-262 [3rd and 5th editions]: The *Identifier *in a
      > *FunctionExpression *can
      > be referenced from inside the *FunctionExpression's FunctionBody *to allow
      > the function to call itself recursively. However, unlike in a *
      > FunctionDeclaration*, the *Identifier *in a *FunctionExpression *cannot be
      > referenced from and does not affect the scope enclosing the *
      > FunctionExpression*.
      >
      > ... so that gets my vote.
      >
      > -- Josh
      >
      > [Non-text portions of this message have been removed]
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.