Variable naming conventions other than trailing underscore [duplicate]

我们两清 提交于 2019-12-07 21:08:36

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19359724/variable-naming-conventions-other-than-trailing-underscore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!