3

I'm reformatting a plug-in so that it passes JSLint. Plug-in uses trailing underscores to name local variables, like so:

var __slice = [].slice,
    __indexOf = [].indexOf

JSLint does not like this. What's another easily recognisable convention for naming these, that JSLint won't object to?

Ila
  • 3,528
  • 8
  • 48
  • 76
  • Is this a plugin you wrote or not? If not, you should be excluding third party files from your linting process. If so, you could just remove the underscores? – James Allardice Oct 14 '13 at 12:10
  • 2
    I didn't write it originally, but I've modified it extensively enough that it needs to be included in my code quality standards, which for this project means passing JSLint. The original is credited in the header per the requirements of the plug-in author. – Ila Oct 14 '13 at 12:14
  • 1
    These are leading underscores, not trailing underscores. –  Jan 03 '16 at 05:57
  • The "solution" of course, is to use a real linter, not one created by a cranky guy trying to impose his personal opinions on everyone. You will find either jshint or eslint a much better choice. For instance, they are much configurable. If this is a corporate policy issue, it is well worth the time to convince your management to switch to a good linter. Based on github start, npm has only 1/10 the popularity of either jshint or eslint. jscs may also be a possibility. But if you are stuck with jslint, did you look at the `nomen` option? –  Jan 03 '16 at 05:59

1 Answers1

4

Quoting from Douglas Crockford, the guy who invented JSLint:

Do not use _ (underbar) as the first character of a name. It is sometimes used to indicate privacy, but it does not actually provide privacy. If privacy is important, use the forms that provide private members. Avoid conventions that demonstrate a lack of competence.

Most variables and functions should start with a lower case letter.

Taken from Code Conventions for the JavaScript Programming Language .

You can look at Private Members in Javascript to see what he meant by use the forms that provide private members.

Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
  • 2
    This isn't answering their question, they're asking for an alternative not for the reasons why it isn't allowed. – Ash Burlaczenko Oct 14 '13 at 12:05
  • 2
    @AshBurlaczenko I think the alternative is present inside the quote: "Most variables and functions should start with a lower case letter." – Ibrahim Najjar Oct 14 '13 at 12:08
  • 1
    That alternative does not satisfy the OP's requirement for an "easily recognisable convention". –  Jan 03 '16 at 06:01
  • could prefix the name: `privateBar = 'boo';` I don't mind the underscore prefix myself... – Ben Creasy Aug 11 '17 at 18:00