JavaScript NG 的思路

chenge · 2013年05月31日 · 3389 次阅读

下面是摘录自 NG 网站。 http://docs.angularjs.org/guide/overview

The Zen of Angular

Angular is built around the belief that declarative code is better than imperative when it comes to building UIs and wiring software components together, while imperative code is excellent for expressing business logic. 简单翻译一下,UI 代码适合于用声明式,业务逻辑适合于用命令式代码。

It is a very good idea to decouple DOM manipulation from app logic. This dramatically improves the testability of the code. DOM 解耦大大提高测试性

It is a really, really good idea to regard app testing as equal in importance to app writing. Testing difficulty is dramatically affected by the way the code is structured.

It is an excellent idea to decouple the client side of an app from the server side. This allows development work to progress in parallel, and allows for reuse of both sides. 前后端解耦,并行开发

It is very helpful indeed if the framework guides developers through the entire journey of building an app: from designing the UI, through writing the business logic, to testing.

It is always good to make common tasks trivial and difficult tasks possible.

Angular frees you from the following pain: 解决四大痛点

注册回调 Registering callbacks: Registering callbacks clutters your code, making it hard to see the forest for the trees. Removing common boilerplate code such as callbacks is a good thing. It vastly reduces the amount of JavaScript coding you have to do, and it makes it easier to see what your application does.

直接操作 DOM Manipulating HTML DOM programmatically: Manipulating HTML DOM is a cornerstone of AJAX applications, but it's cumbersome and error-prone. By declaratively describing how the UI should change as your application state changes, you are freed from low level DOM manipulation tasks. Most applications written with Angular never have to programmatically manipulate the DOM, although you can if you want to.

同步数据和 UI Marshaling data to and from the UI: CRUD operations make up the majority of AJAX applications. The flow of marshaling data from the server to an internal object to an HTML form, allowing users to modify the form, validating the form, displaying validation errors, returning to an internal model, and then back to the server, creates a lot of boilerplate code. Angular eliminates almost all of this boilerplate, leaving code that describes the overall flow of the application rather than all of the implementation details.

太多的初始化代码 Writing tons of initialization code just to get started: Typically you need to write a lot of plumbing just to get a basic "Hello World" AJAX app working. With Angular you can bootstrap your app easily using services, which are auto-injected into your application in a Guice-like dependency-injection style. This allows you to get started developing features quickly. As a bonus, you get full control over the initialization process in automated tests.

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号