Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top