Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh-cn: init the translation of "camel case" #17086

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions files/zh-cn/glossary/camel_case/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 驼峰式命名法
slug: Glossary/Camel_case
l10n:
sourceCommit: 6aa664dc5ccb5edf0897f99ad5feb59325dff831
---

{{GlossarySidebar}}

**驼峰式命名法**(Camel case)是一种不使用空格的短语书写方式,除了整个复合单词的首字母可以是大写或小写的之外,其他每个单词的首字母大写。该名称源于大写字母与骆驼背部的驼峰的相似性。它通常被写作“camelCase”,以提醒读者其外观。

驼峰式命名法通常用作变量命名约定。以下变量使用了驼峰式命名法:{{domxref("console")}}、{{domxref("crossOriginIsolated")}}、{{jsxref("encodeURIComponent")}}、{{jsxref("ArrayBuffer")}} 和 {{domxref("HTMLElement")}}。

注意,如果短语包含缩写(例如 `URI` 和 `HTML`),驼峰式命名法的做法会有所不同。有些人喜欢保持所有缩写大写,例如上面的 `encodeURIComponent`。这有时会导致多个连续缩写的歧义,例如 `XMLHTTPRequest`。其他人则喜欢只大写第一个字母,例如 `XmlHttpRequest`。实际的全局变量 {{domxref("XMLHttpRequest")}} 使用了两者的混合。

当整个短语的第一个字母是大写时,它被称为*大驼峰式*(upper camel case)或*帕斯卡式*(Pascal case)。否则,它被称为*小驼峰式*(lower camel case)。

驼峰式命名法是 JavaScript、Java 和其他各种语言中最流行的命名约定。

## 参见

- [蛇形命名法](/zh-CN/docs/Glossary/Snake_case)
- [烤串命名法](/zh-CN/docs/Glossary/Kebab_case)
- [typescript-eslint 规则:`naming-convention`](https://typescript-eslint.io/rules/naming-convention/)