Dojo frame: misunderstanding and reality



With the popularity of Ajax technology, more and more Web applications use Ajax technology to improve user experience. An important advantage of using Ajax technology is that there is no need for additional browser plug-in support, just use the browser’s native API, and use JavaScript to operate. The two big problems encountered when using native APIs are browser compatibility and the programming complexity brought by the underlying A-generation PI interface. There are differences in the way the same function is implemented on different browsers. If an application wants to support different browsers, developers need to add a lot of browser detection or sniffing code. For example, for the same event binding function, attachEvent is used on IE, and addEventListener is used on other browsers. In addition to compatibility issues, the native API interfaces provided by browsers are generally more suitable for performing fine-grained operations. When you need to complete some relatively complex operations, using the native API interface will make the code more cumbersome. Take a DOM query as an example: Find all the direct child nodes of a given label of a node with a given ID in the current document tree. For such a query, if you use the native DOM API, you will need to use getElementById to find the node, get the list of child nodes through childNodes, and compare the label names of the nodes. The amount of code required will be relatively large.

The emergence of JavaScript frameworks is precisely to solve these two relatively large problems, and different JavaScript frameworks also provide their own additional value. There are so many JavaScript frameworks that can be used at present, and there are more than ten popular ones. These popular JavaScript frameworks include jQuery, Dojo, YUI, MooTools, Prototype, Ext JS, Google Closure, etc. These different frameworks have their own different advantages and disadvantages, and also have corresponding different applicable scenarios and scopes. Due to work, the author uses the Dojo framework the most, and has a certain understanding of other frameworks. The purpose of this article is to clarify some misunderstandings about the Dojo framework, so as to help developers choose the right framework.

Before we start, let’s briefly introduce the basic structure of the Dojo framework. The Dojo framework consists of four parts: Dojo basic library, core library, Dijit and extended library. The basic library contains the most basic functions, the core library is an extension of the basic library, Dijit is the user interface library, and the extension library is a variety of extension components.

Meet the basic needs of Ajax application development

Like other frameworks, Dojo tries to meet the most basic needs of Ajax application development. These basic requirements include the aforementioned browser compatibility and native API interface granularity issues, as well as some typical application scenarios. Specifically, it should include the following feature sets: JavaScript language enhancement, XMLHttpRequest encapsulation, DOM query and operation, and event handling. The browser compatibility is reflected in the effect of these feature sets on different browsers.

From the Dojo framework, the support for these feature sets is relatively rich. In terms of JavaScript language enhancements, there are many enhancements to numbers, strings, date types, arrays, and JavaScript methods. In terms of I/O transmission, in addition to the commonly used XMLHttpRequest, iframe and