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

"Use a named function" error

Expand Messages
  • Jordan
    ... /*jslint browser: true, onevar: true, undef: true, white: true, newcap: true */ var somefunc = function () { ....var self = { ........method: function () {
    Message 1 of 3 , Jul 6 12:23 PM
    • 0 Attachment
      With this code:
      ---------------
      /*jslint browser: true, onevar: true, undef: true, white: true, newcap: true */

      var somefunc = function () {
      ....var self = {
      ........method: function () {
      ............// do something
      ............return self; // for chaining
      ........}
      ....};
      ....return self;
      },
      somefunc().method().method();
      --------------
      I get the error "Problem at line 7 character 20: Use a named function self."

      When I remove the `somefunc` code, and just declare the `self` object, the error does not occur.

      I believe this error is attempting to refer to recursion, which is not what I'm doing here. Is this an error in JSLint?

      - Jordan
    • Douglas Crockford
      ... Thanks. Please try it now.
      Message 2 of 3 , Jul 6 5:18 PM
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Jordan" <ljharb@...> wrote:

        > var somefunc = function () {
        > ....var self = {
        > ........method: function () {
        > ............// do something
        > ............return self; // for chaining
        > ........}
        > ....};
        > ....return self;
        > },
        > somefunc().method().method();
        > --------------
        > I get the error "Problem at line 7 character 20: Use a named function self."
        >
        > When I remove the `somefunc` code, and just declare the `self` object, the error does not occur.

        Thanks. Please try it now.
      • Jordan
        Works perfectly, thanks!
        Message 3 of 3 , Jul 6 8:11 PM
        • 0 Attachment
          Works perfectly, thanks!

          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "Jordan" <ljharb@> wrote:
          >
          > > var somefunc = function () {
          > > ....var self = {
          > > ........method: function () {
          > > ............// do something
          > > ............return self; // for chaining
          > > ........}
          > > ....};
          > > ....return self;
          > > },
          > > somefunc().method().method();
          > > --------------
          > > I get the error "Problem at line 7 character 20: Use a named function self."
          > >
          > > When I remove the `somefunc` code, and just declare the `self` object, the error does not occur.
          >
          > Thanks. Please try it now.
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.