Search code examples
javascriptjslint

JSLint - ignore missing function name


I am trying to evaluate an anonymous JavaScript function using JSLint. However, JSLint fails evaluating it because the function is missing a name. What option can I set to allow JSLint to ignore that error?

Something like:

function(test) {
    return;
}

Results in:

Missing name in function statement.
function(test) {

EDIT: To clarify, the anonymous function will be used as a view for CouchDB. I want to ensure that the syntax is correct before it hits the DB.


Solution

  • You can make a JavaScript function non-anonymous by using one of the following techniques:

    1. Give the function a name:

      function myFunction(test) {
          return;
      }
      
    2. Assign the function to a variable:

      var myFunction = function(test) {
          return;
      }
      
    3. In fact, you can combine both approaches, but i wouldn't recommend that:

      var myFunction = function myFunction(test) {
          return;
      }