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

1423[jslint] Re: Calling With Too Much Parameters

Expand Messages
  • pauanyu
    Aug 12, 2010
    • 0 Attachment
      Just one question... how is that function any different from this one?

      var f = function (a, b) {
      // ...
      };

      --- In jslint_com@yahoogroups.com, Rob Richardson <erobrich@...> wrote:
      >
      > This is totally valid (albeit confusing):
      >
      > var f = function () {
      > // FRAGILE: Error check arguments.length and resulting vars for presence of
      > value before using
      > var a = arguments[0];
      > var b = arguments[1];
      > ...
      > }
      >
      > A function like this could correctly be called in all these cases:
      >
      > f(1,2,3,4,5);
      >
      > f(1,2,3);
      >
      > f({a: 1, b: 2, c: 3});
      >
      > f();
      >
      > The jQuery UI suite uses this technique a lot -- optionally pass in a settings
      > initialization object on first run, pass in a setting name and get back the
      > current value, pass in a setting name and a new value to set it. The main
      > jQuery framework also uses this technique a lot.
      >
      > I like the idea of JSLint knowing that a function was called with a different
      > number of arguments than it accepts or with arguments that don't match the
      > definition, but because function overloading is a standard API development
      > technique, I can see it easily becoming more distracting than helpful. If it
      > could also parse my docs and validate usages match my intent ... and drive my
      > car and clean my kitchen and read my mind. :D It seems a carefully built set
      > of unit tests that run on each commit better accounts for potential mistakes in
      > this arena.
      >
      > Rob
      >
      >
      > ________________________________
      > From: Jean-Charles Meyrignac <jcmeyrignac@...>
      > To: jslint_com@yahoogroups.com
      > Sent: Tue, August 10, 2010 11:57:59 PM
      > Subject: Re: [jslint] Re: Calling With Too Much Parameters
      >
      >
      > On Wed, Aug 11, 2010 at 7:49 AM, pauanyu <pcxunlimited@...> wrote:
      >
      > >
      > >
      > > Don't forget that it's possible to access the non-named parameters using
      > > the "arguments" object.
      > >
      > > Thanks, I forgot that.
      >
      > > I suppose if the function does not access the arguments object, then
      > > throwing a warning or error in that case might be nice.
      > >
      > > A warning is enough, and would help locating weird calls.
      >
      > > In any case, if the function is called with more arguments than it expects,
      > > it simply ignores the excess. I'm not sure why that would cause a bug in the
      > > plugin.
      > >
      > > The routine was called with arguments (url, login, password, callback).
      > And the routine was declared with (url, server, callback), with server =
      > {login, password}
      > So 'password' was used instead of 'callback'.
      > It seems that a refactoring gone wrong..
      >
      > JC
      >
    • Show all 8 messages in this topic