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

Re: Anonymous callback in prototype

Expand Messages
  • Douglas Crockford
    ... JSLint tries to guess a name for anonymous functions. Guessed names are wrapped in quotes. You should only use /*global */ for names that are defined
    Message 1 of 3 , Aug 10, 2009
      --- In jslint_com@yahoogroups.com, "cdcmicro" <cdcmicro@...> wrote:
      > I'm not sure this is a problem, or if I'm just reading the report wrong. When creating an anonymous function (a callback) as an arg to a function:
      >
      > /*global myparams, myfunc */
      > myfunc(myparams, function (cbdata) {
      >
      > });
      >
      > function myfunc (params, callback) {
      > return callback();
      > }
      >
      > The report indicates:
      >
      > 2-4 "myparams"(cbdata)
      >
      > 6-8 myfunc(params, callback)
      >
      > as if myparams is the function name, but not really.

      JSLint tries to guess a name for anonymous functions.
      Guessed names are wrapped in quotes.

      You should only use /*global */ for names that are defined
      outside of the file. So,

      /*global myparams */

      function myfunc(params, callback) {
      return callback();
      }

      myfunc(myparams, function (cbdata) {

      });
    • cdcmicro
      ... Got it. I understand now about the quoted, guessed name. Thanks for the quick clarification. -Clark
      Message 2 of 3 , Aug 10, 2009
        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
        >
        > --- In jslint_com@yahoogroups.com, "cdcmicro" <cdcmicro@> wrote:
        > > I'm not sure this is a problem, or if I'm just reading the report wrong. When creating an anonymous function (a callback) as an arg to a function:
        > >
        > > /*global myparams, myfunc */
        > > myfunc(myparams, function (cbdata) {
        > >
        > > });
        > >
        > > function myfunc (params, callback) {
        > > return callback();
        > > }
        > >
        > > The report indicates:
        > >
        > > 2-4 "myparams"(cbdata)
        > >
        > > 6-8 myfunc(params, callback)
        > >
        > > as if myparams is the function name, but not really.
        >
        > JSLint tries to guess a name for anonymous functions.
        > Guessed names are wrapped in quotes.
        >
        > You should only use /*global */ for names that are defined
        > outside of the file. So,
        >
        > /*global myparams */
        >
        > function myfunc(params, callback) {
        > return callback();
        > }
        >
        > myfunc(myparams, function (cbdata) {
        >
        > });
        >

        Got it. I understand now about the quoted, "guessed" name. Thanks for the quick clarification.

        -Clark
      Your message has been successfully submitted and would be delivered to recipients shortly.