The use of jquery began to become the main selection of JavaScript developers, but without a whole plan, simple copycat is bound to bring later maintenance costs, a large number of jquery plug-ins like a double-edged sword, on the one hand, greatly saving the development time and cycle, But at the same time also caused the burden of Web page loading, the difficult to protect and two-level expansion costs will be very large, so before using a most basic JavaScript architecture system, can be significantly basic functional components, plug-in components effective implementation and expansion.
We think, after all, jquery is just a base of the lowest toolset, encapsulation element selector, events and so on, basically to meet the general requirements, but from the overall web of the week, in order to improve the efficiency of JavaScript development and reusability, you need to have a whole layout, Biuuu that the simplest ideas are as follows:
1, on the existing Ajax interface to encapsulate a layer of operations, mainly used to unify the Ajax entrance, at the same time can subdivide the get and post two kinds of separation, through the global entrance, can be from the collation, such as filter parameters, test parameters, increase global parameters, one-step, very high reusability, The implementation is as follows:
Copy Code code as follows:
var ajax= {
Get:function () {
Jquery.get (URL, [data], [callback], [type])
}
Post:function () {
Jquery.post (URL, [data], [callback], [type])
}
}
2, the package of unified pop-up box, dialog boxes and other interactive windows, through the unified interface to achieve the interaction of window type operation, save development time, at the same time conducive to the overall style of adjustment and optimization.
3, provide the basic plug-in load function, similar to Factory mode, unified plug-in load and call the entrance, for the later expansion and maintenance of convenience, so you do not need to care about the update and upgrade plug-ins, only need to call the unified interface.
4, is actually some of the most basic functions commonly used, which is related to specific projects, as a global tool class.
From the above four point of view, the overall framework of ideas is only a relatively shallow level of the scheme, in fact, there are security, performance and other aspects of consideration, but at least need to have this idea, the more simple it can reflect the rationality of the architecture, JavaScript system is no exception, in the actual use of the process, through integration and optimization, It is easy to improve JavaScript development efficiency and improve JavaScript capabilities.