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

2859Early Unused Arguments

Expand Messages
  • benquarmby
    Apr 22, 2012
    • 0 Attachment
      I realize the topic of unused arguments has been discussed before, but I wanted to raise it again with a suggested alternative behavior.

      When creating callbacks / event handler functions for an API, you rarely have control over the expected number of arguments, nor their order. While it would be great if all these APIs passed a single object as the first argument, the reality is that they usually pass up to three separate arguments instead.

      In that case, if you only use the second of those three, the first must still be provided. JSLint naturally warns about these early unused arguments. At the moment the team I work with manually adds comments to avoid warnings, but it quickly becomes unwieldy.

      So, I'd like to know your thoughts on allowing unused arguments before a used one, but not after. In other words, the following would not cause a warning:

      MY_API.binder(someElement, 'click', function (a, b) {

      The following would raise an "Unused Variable 'c'" warning:

      MY_API.binder(someElement, 'click', function (a, b, c) {

      Thoughts? Could it be a new toleration?
    • Show all 11 messages in this topic