什么是最佳实践的外壳风格的JavaScript?为什么? [英] What is the best-practice casing style for javascript? Why?

查看:164
本文介绍了什么是最佳实践的外壳风格的JavaScript?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript的一个方面是很难找到关于套管实践的信息。通过套管实践,我的意思是什么样的套管风格(即骆驼案件,帕斯卡案例等)应该用于什么元素(构造函数,私有函数,公共函数)。



我听过的唯一规则是来自YUI剧院的道格拉斯克罗克福德讲座,指出构造函数应该是唯一以大写字母开头的函数。



除此之外,人们在javascript中看起来并没有很多标准。

有没有人了解JavaScript的任何套管最佳实践,以及为什么它使用它们是合理的?



您也可以使用.js文件的套用风格吗?

解决方案

我更喜欢PascalCase的构造函数和camelCase的一切。这是JS标准库使用的风格,以及我到目前为止所见过的每个JS框架:)

我使用all_lowercase命名约定来处理所有文件网页。这里有一些不区分大小写的文件系统。


One aspect of javascript that it's hard to find information on is casing practices. By casing practices, I mean what casing style (ie. camel-case, pascal-case, etc) should be used for what elements (Constructors, private functions, public functions).

The only rule I've heard was from a Douglas Crockford lecture on YUI theater, stating that constructors should be the only functions that start with an uppercase letter.

Beyond that there doesn't seem to be many casing standards that people follow in javascript.

Does anyone know any casing best practices for javascript, and why it's reasonable to use them?

Also do you follow a casing style with your .js files?

解决方案

I prefer PascalCase for constructors and camelCase for everything else. That's the style that JS standard library uses and well... every JS framework I've seen so far :)

And I use all_lowercase naming convention for all files served from web. There are some case-insensitive file systems out there.

这篇关于什么是最佳实践的外壳风格的JavaScript?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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