JavaScript对象的大写约定 [英] Capitalization convention for JavaScript objects

查看:97
本文介绍了JavaScript对象的大写约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题没有答案,但我很想知道其他人的想法。

I know this question has no answer, but I'm curious to know what other people think.

在像Java这样的语言中,开始上课是一种惯例大写字母和小写字母的对象。但是那些一切都是对象的JavaScript怎么样?

In a language like Java, it's a convention to begin classes with capital letters, and objects with lowercase letters. But what about JavaScript, where everything is an object?

我看到有些人建议只使用被视为类的对象;即具有原型的函数对象,旨在与 new 运算符一起使用。这些对象的实例将是小写的。

I've seen some people suggest capitalizing only objects that are treated as classes; i.e. function objects with a prototype, that are intended to be used with the new operator. Instances of those objects would be lowercased.

这听起来合乎逻辑。但是你对全局对象做了什么呢,那里只有一个实例?大多数人似乎都将这些资本化(例如,数学 Ext.History )。这种直觉感觉很合适,但很难用一致的规则来证明它。

That sounds logical. But what do you do about "global objects", where there's only one instance? Most people seem to capitalize these (for example, Math or Ext.History). This intuitively feels right, but it's hard to justify it with a consistent rule.

那么用作名称空间的对象呢?这些似乎遍布地图: YUI Ext.util jQuery 等。

And what about objects that are used as namespaces? These seem to be all over the map: YUI, Ext.util, jQuery, etc.

请为您心中的宗教观点提供世俗的理性化。

Please provide secular rationalizations for your heart-felt religious views.

推荐答案

您可以按照 Google JavaScript样式指南

一般情况下,请使用functionNamesLikeThis,variableNamesLikeThis,ClassNamesLikeThis,EnumNamesLikeThis,methodNamesLikeThis,和SYMBOLIC_CONSTANTS_LIKE_THIS。

In general, use functionNamesLikeThis, variableNamesLikeThis, ClassNamesLikeThis, EnumNamesLikeThis, methodNamesLikeThis, and SYMBOLIC_CONSTANTS_LIKE_THIS.

这篇关于JavaScript对象的大写约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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