JavaScript命名约定 [英] JavaScript naming conventions

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

问题描述

我知道有很多争议(可能没有争议,但至少是争论)关于哪种命名约定最适合JavaScript。

I know there is a lot of controversy (maybe not controversy, but arguments at least) about which naming convention is the best for JavaScript.

你怎么命名你的变量,函数,对象等吗?

How do you name your variables, functions, objects and such?

我会对此有所了解,因为我没有长时间使用JS(几年,我只是请求创建一个文档,其中包含在我们的工作项目中使用的命名约定。所以我一直在寻找(google-ing),并且有很多不同的意见。

I’ll leave my own thoughts on this out, as I haven’t been doing JS for long (couple of years, only), and I just got a request to create a document with naming conventions to be used in our projects at work. So I’ve been looking (google-ing) around, and there are so many different opinions.

我在JS上阅读的书籍本身也使用不同的命名约定,但他们都同意一点:找到适合你的东西,并坚持下去。但是现在我已经阅读了这么多,我发现我喜欢其他一些方法比我更好以前。

The books I’ve read on JS also use different naming conventions themselves, but they all agree on one bit: "Find what suits you, and stick to it." But now that I’ve read so much around, I found that I like some of the other methods a bit better than what I’m used to now.

推荐答案

我按照道格拉斯克罗克福德的javascript代码约定。我还使用他的 JSLint 工具来验证这些约定。

I follow Douglas Crockford's code conventions for javascript. I also use his JSLint tool to validate following those conventions.

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

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