除尾随下划线之外的可变命名约定 [英] Variable naming conventions other than trailing underscore

查看:68
本文介绍了除尾随下划线之外的可变命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新格式化一个插件,以便它传递JSLint。插件使用尾部下划线来命名局部变量,如下所示:

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不喜欢这样。
命名这些的另一个易于识别的约定是什么,JSLint不会反对?

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

推荐答案

引自Douglas Crockford发明JSLint的人:

Quoting from Douglas Crockford, the guy who invented JSLint:


不要使用_(underbar)作为名字的第一个字符。有时用于表示隐私的是
,但它实际上并不提供
隐私。如果隐私很重要,请使用提供私人
成员的表格。避免表现出缺乏能力的惯例。

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.

取自 JavaScript编程语言的代码约定

您可以在Javascript中查看私人会员看看的意思是使用提供私人会员的表格。

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

这篇关于除尾随下划线之外的可变命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆