ES6中const对象键的命名约定 [英] Naming convention for const object keys in ES6

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

问题描述

es6中const对象中的键名是否有推荐的命名约定?我无法找到一个资源,说明它们应该是大写还是小写。

Is there a recommended naming convention for key names within a const object in es6? I haven't been able to find a resource which states if they should be uppercase or lowercase.

const COLOR_CODES = {
  BLUE: 1,
  RED: 1
};

vs

const COLOR_CODES = {
  blue: 1,
  red: 1
};

来自这篇MDN文章的示例显示了这两种风格,所以两者都可以接受。

The examples from this MDN article show both styles, so maybe both are acceptable.

推荐答案

根据谷歌的说法,它将全部上限。根据经验,大多数其他编程语言都有上限,所以我建议使用它。

According to Google it would be all caps. Speaking from experience, most of the other programming languages have all caps so I would suggest using that.

使用 NAMES_LIKE_THIS 对于常量值。

使用 @const 表示一个常量(不可重写)指针(变量或属性) )。

Use @const to indicate a constant (non-overwritable) pointer (a variable or property).

谷歌javascript指南
https://google.github.io/styleguide/javascriptguide.xml

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

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