最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to organize complex jquery application? - Stack Overflow

programmeradmin5浏览0评论

So I have a problem with my jquery applications entirely. When the application is small it's cool. But when it is quite large it is such a mess.. Nested functions, ajax calls, selectors, dom manipulations. Seems like it's non-containable at all, especially when it has a plex logic.

The functional approach does not help me out much. And I don't see how to use classes and inheritance here in practice. How to organize the code? I have read a lot of articles about prototypical and pseudo classical inheritance but they just explain how things works, like how you can inherit 'Person' from 'Human' or something like this. How can I actually use it in real life?

So I have a problem with my jquery applications entirely. When the application is small it's cool. But when it is quite large it is such a mess.. Nested functions, ajax calls, selectors, dom manipulations. Seems like it's non-containable at all, especially when it has a plex logic.

The functional approach does not help me out much. And I don't see how to use classes and inheritance here in practice. How to organize the code? I have read a lot of articles about prototypical and pseudo classical inheritance but they just explain how things works, like how you can inherit 'Person' from 'Human' or something like this. How can I actually use it in real life?

Share Improve this question edited Jul 10, 2012 at 0:20 Aleksandra Zalcman 3,4981 gold badge21 silver badges19 bronze badges asked Aug 4, 2011 at 21:23 Grom SGrom S 2395 silver badges10 bronze badges 1
  • +1 Exactly how I feel right now. Anything to share since you made this question? – theblang Commented Dec 11, 2012 at 16:32
Add a ment  | 

2 Answers 2

Reset to default 6

I find two things that really help organize javascript. One use objects for encapsulation ( http://www.dustindiaz./namespace-your-javascript ), and two, write a library for mon tasks. The normal refactoring strategies work for javascript, extract functions, monize, if you have 4 functions doing nearly the same thing, change them to a single function which can handle all four cases.

When planning a large jQuery application that I'm currently working on, I found this post by Addy Osmani very useful.

Full disclosure, though: we ended up hanging most of our application backbone off of a YUI3 core. All our "controller" code is written in jQuery, but the frontend data model is YUI3.

发布评论

评论列表(0)

  1. 暂无评论