backbone.js 有哪些命名约定?
我知道这并不重要,但我只是好奇人们如何命名他们的模型/集合/视图/路由器功能。
I know it is not that important, but I am just curious as to how people name their models / collections / views / router functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一切都取决于模型、集合等代表什么以及它们在结构上如何使用。
我通常给我的模型一个通用名称,然后为所有其他模型添加其构造函数类型的后缀
Ex:
现在,您只需传递它的模型即可创建一个新的动物视图,并且其他阅读您代码的人可以轻松理解该模型代表什么。
当然,您也可以随时在模型后加上 Model 一词,但我认为没有它就足够好了,因为模型代表具有属性的单个平面对象,而不是某种视图或集合。对象。
That all depends on what the model, collection, etc represents and how they are used structurally.
I typically give my models a generic name and then suffix all others with their constructor type
Ex:
Now you can create a new animal view simply by passing it it's model and other people who read your code can easily understand what the model represents.
Of course, you can always suffix your models with the word Model as well, but I think it speaks well enough without it since a model represents a single flat object with properties not some sort of view or collection of objects.