处理较大项目上的javascript的方法? [英] Approach to handle javascript on bigger projects?

查看:82
本文介绍了处理较大项目上的javascript的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前发现jQuery之后,我意识到了真正地制作交互式且用户友好的网站而无需编写代码书是多么容易.随着项目规模的增加,进行任何调试或实施更改或新功能所需的时间也增加了.

After discovering jQuery a few years ago, I realized how easy it was to really make interactive and user friendly websites without writing books of code. As the projects increased in size, so did also the time required to carry out any debugging or perhaps implementing a change or new feature.

通过阅读各种博客并保持一定的更新,我已经了解到与 Backbone.js JavascriptMVC 听起来都是不错的选择,以使代码更加模块化和独立.

From reading various blogs and staying somewhat updated, I've read about libraries similar to Backbone.js and JavascriptMVC which both sound like good alternatives in order to make the code more modular and separated.

但是,与Java或jQuery专家相距甚远,我真的不适合讲述优先考虑未来易维护性,调试和开发的项目中什么是良好的基石.

However as being far from an Javascript or jQuery expert, I am not really not suited to tell what's a good cornerstone in a project where future ease of maintainability, debugging and development are prioritized.

因此,请记住这一点-在启动以Javascript和jQuery代表大多数用户体验和向用户呈现数据的项目时,常识是什么?

非常感谢

推荐答案

Backbone.js和JavascriptMVC都是使用框架以理智的方式组织大型项目的绝佳示例( Cappuccino 也很好).我绝对建议您选择一种标准方法来处理来自服务器的数据,处理来自DOM的事件和来自服务器的响应以及视图创建.否则,这可能是一场维护噩梦.

Both Backbone.js and JavascriptMVC are great examples of using a framework to organize large projects in a sane way (SproutCore and Cappuccino are nice too). I definitely suggest you choose a standard way of deal with data from the server, handling events from the DOM and responses from the sever, and view creation. Otherwise it can be a maintenance nightmare.

除了MVC框架之外,您可能还应该为这些问题选择解决方案:

Beyond an MVC framework, you should probably choose a solution for these problems:

  • 依赖性管理:如何以正确的顺序编译和加载javascript文件?我的建议是 RequireJS .
  • 测试:测试UI代码从来都不是一件容易的事,但是jQuery的家伙已经做了一段时间了,他们的测试工具 QUnit 有据可查/经过测试.
  • 缩小:在部署到生产环境之前,您需要缩小代码,但RequireJS内置了此功能,但您也可以使用关闭编译器,如果您想获取疯狂的小资源.
  • 构建系统:所有这些工具都很不错,但是您应该将它们全部整合到一个主构建系统中,这样您就可以在命令行上运行一个简单的命令并调试或生产应用程序.具体使用的工具取决于您选择的语言-Ruby => Rake ,Python->编写您自己的代码, NodeJS 作为构建工具(我最喜欢此选项)-> Jake
  • Dependency management: how will you compile and load javascript files in the right order? My suggestion would be RequireJS.
  • Testing: testing UI code is never easy but the guys over at jQuery have been doing for a while and their testing tool QUnit is well documented/tested.
  • Minification: you'll want to minify your code before deploying to production RequireJS has this built in but you could also use the Closure Compiler if you want to get crazy small source.
  • Build System: All these tools are great but you should pull them all together in one master build system so you can run a simple command on the commandline and have you debug or production application. The specific tool to use depends on your language of choice - Ruby => Rake, Python -> Write your own, NodeJS as a build tool (i like this option the most) -> Jake

除此之外,请注意是否感到笨拙或缓慢(无论是工具还是框架)并进行重构.

Beyond that just be aware if something feels clunky or slow (either tooling or framework) and refactor.

这篇关于处理较大项目上的javascript的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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