为什么JavaScript文件名有时有点?
我有以下问题,这是因为有点数的JavaScript文件名吗?
例如:
在带有Express的节点JS项目中,我找到了以下文件:
user.route.js
user.controller.js
I have the following question and is it because there are javascript file names with dots?
For example:
In a node js project with express, I found the following files:
user.route.js
user.controller.js
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为在阅读文件名时很清楚,您可以知道文件的责任,对象正在处理,项目的业务模型。
轻松维护,修复错误。
Because it very clearly when you read the filename, you can know the responsibility of file, object is handling, Business model of project.
Easy maintain, fix bug.
这是将文件放在不同目录中的同样原因。我们为什么要这样做?我们想以可管理的方式组织文件。因此,我们将与路由相关的文件放在
路由
目录,Service> Service
目录中的业务逻辑相关文件中。组织文件的另一种方法是将名称本身中提到的文件的类型。文件名
user.route.js
说,它包含路由
与用户
有关。文件user.controller.js
说,它包含Controller
与用户
有关的功能。如果您对此有更多的考虑,则类似于文件名中的扩展名。文件以
.js
告诉我们,它是javascript
文件。.css
,.html
等文件也是如此。同样,文件以.route.js
告诉我们,它是一个具有相关JavaScript代码的文件。那么,以.controller.js
结尾的文件告诉您什么?It is the same reason why you put files in different directories. Why would we do that? We want to organize the files in a manageable manner. So, we put routing related files in
routes
directory, business logic related files inservice
directory.Another way of organizing files is to have the type of the file mentioned in the name itself. The file name
user.route.js
says, it containsroutes
related touser
. The fileuser.controller.js
says, it containscontroller
functions related touser
.If you think more about it, it is similar to having extensions in file names. Files ends with
.js
tells us, it is aJavaScript
file. Same goes for.css
,.html
, etc files. The same way, files ends with.route.js
tells us, it is a file that has routing related JavaScript code. So, what does files that ends with.controller.js
tells you?