Dojo Learning Notes 1. Modules and Packages

Source: Internet
Author: User
Tags require split svn versions

Dojo is a very powerful object-oriented JavaScript toolbox, suggesting that readers should be able to add JavaScript to programming with OO, which is very useful for you to read Dojo source later.

Getting Started

1: Add Dojo to our web program

1. Logo<script type="text/javascript">
djConfig = { isDebug: false };
</script>

Djconfig is a global object in dojo that provides various options for dojo, Isdebug is one of the most commonly used properties, set to True to see the debug output directly on the page, and of course some of the properties are related to debugging.

2. Referencing Dojo's boot code

<script type= "Text/javascript" src= "/yourpath/dojo.js"/>

So you reference the dojo code, and you can directly use some of the commonly used objects, downloaded dojo.js is the compression (remove comments and space) after the code, to read, suggest reading Dojo.js.uncompressed.js, Dojo.js about 127K, and not compressed before there are 211K, OK, why so large, it has been part of the commonly used modules into the dojo.js, so it appears a bit larger, build.txt the default dojo.js contains what modules

3. Declare the bag you want to use

<script type="text/javascript">
 dojo.require("dojo.math");
 dojo.require("dojo.io.*");
 dojo.require("dojo.widget.*");
</script>

You just think of the code as a Java import statement or a using statement in C #, and if you don't require, and the module itself is not integrated in Dojo.js, there's a script error.

2. Pre-integration packages for different needs

Dojo itself is made up of a number of modules, but because of the variety of user requirements, Dojo offers different versions for different requirements, and users can download dojo with a choice of many versions, such as Ajax and widget editions, The most important difference for each version is the Dojo.js file, but in addition, each version is fully functional, dojo.js is integrated into different modules according to the version

3. Get the latest source code for dojo directly

First you have to install subversion, and when subversion is working on your computer, you can download Dojo's source code by following these commands:

SVN Co http://svn.dojotoolkit.org/dojo/trunk/

This will create a trunk directory under your current directory; If you want to direct get to the current directory, use this command:

SVN co http://svn.dojotoolkit.org/dojo/trunk/.

Or you want to get to the Mydir directory under the current directory, with this command:

SVN Co http://svn.dojotoolkit.org/dojo/trunk/MyDir

Modules and Packages

Module

Dojo's code is divided into a logical unit called a module, which is somewhat similar to the package in Java, except that Dojo's modules can contain classes (similar to classes in Java) and simple functions

For example: the module "dojo.html" contains a series of functions, such as Dojo.html.getContentBox (), module "DOJO.DND" contains a series of htmldragobject classes

Note the name convention, the first letter of the function is a lowercase letter, the first letter of the class is uppercase

Modules can also be called "namespaces"

Package

In most cases, Dojo's modules only need to be defined in a file on it, but sometimes, a module may be divided into multiple files, such as: module dojo.html, originally defined in a file, but because of enhancements, the file gradually become larger, we have to split it into multiple files, This is primarily for performance reasons, so that browsers can download only the code they need, and unfortunately its implementation details don't seem so transparent to dojo users, you have to know which file you want to use, and then you can require and use it.

Each of these files is called a package

Dojo.require ("Dojo.html.extras")

Will refer to the file src/html/extras.js, which defines several (not all) functions of the module dojo.html

As far as I know, although a single file can define multiple classes in a package, a single script file cannot define multiple modules (in Java it can be equivalent to defining 2 classes in a file), and the name of the package and the name of the module can be different, such as: The package Dojo.widget.Button defines the Dojo.widget.html.Button

Basically you should think that the package and module, though closely related, are two completely different entities

Why is there a concept of modules and packages?

Why is there a concept of modules and packages? In order to meet the needs of your application just to load the things it uses, taking advantage of the advantages of modular design, Dojo maintains the smallest footprint to still provide the functionality you need, why should your users waste time downloading JavaScript that is not in use, when a package is a JS file, A module is essentially a namespace, such as: Dojo.style or Dojo.html.extras

In most simple cases, a package contains a module, but more often, a module may be split into several package files

Using packages and modules, will ensure that you can deliver the most relevant functional code, minimize code bloat, and eliminate the resulting bad user experience, which is the main goal of module design, through modularity, you can introduce custom modules (your own JavaScript tools), and the maintenance module will have little impact on the core code base.

In addition, the Dojo module system also provides built-in mechanisms to use code to provide namespaces, such as Dojo's event systems defined through module dojo.event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.