dojo 二 AMD模块
可参考官方教程:http://dojotoolkit.org/documentation/tutorials/1.7/hello_dojo/
教程里主要定义了两个方法,setText设置文本内容和restoreText重置文本内容。
这两个方法通过dojo.define这个方法来定义。
// In
demo/myModule.js (which means this code defines// the
"demo/myModule" module):define([ // The dojo/dom module is required by this
module, so it goes // in this list of
dependencies. "dojo/dom"],
function(dom){ // Once all modules in the dependency list
have loaded, this // function is called to define the
demo/myModule module. // // The dojo/dom module is passed as the
first argument to this // function; additional modules in the
dependency list would be // passed in as subsequent
arguments. var oldText =
{}; // This returned object becomes the defined
value of this module return { setText:
function(id, text){ var node =
dom.byId(id); oldText[id] =
node.innerHTML; node.innerHTML =
text; }, restoreText:
function(id){ var node =
dom.byId(id); node.innerHTML =
oldText[id]; deleteoldText[id]; } };});
define 方法引用了必要的类,就像java 中的
import;并且还包含了对业务逻辑的实现,
并通过return来返回,以上就是myModule.js文件的全部内容。
那么在html页面里,通过dojo.require来加载上面的js代码,
//
Require the module we just createdrequire(["demo/myModule"],
function(myModule){ // Use our module to change the text in the
greeting myModule.setText("greeting",
"Hello Dojo!"); // After a few seconds, restore the text to
its original state setTimeout(function(){ myModule.restoreText("greeting"); }, 3000);});加载成功后就可以通过 myModule.setText
这样的方式来调用了。
在这里暂且先总结为:dojo.define 方法仅用于定义和声明,dojo.require 方法仅用于异步加载js文件
dojo 二 AMD模块的更多相关文章
- Dojo初探之2:设置dojoConfig详解,dojoConfig参数详解+Dojo中预置自定义AMD模块的四种方式(基于dojo1.11.2)
Dojo中想要加载自定义的AMD模块,需要先设置好这个模块对应的路径,模块的路径就是这个模块的唯一标识符. 一.dojoConfig参数设置详解 var dojoConfig = { baseUrl: ...
- AMD模块介绍(翻译)
http://dojotoolkit.org/documentation/tutorials/1.10/modules/index.html Dojo支持以异步模型定义(AMD)方式编写的模块,让会让 ...
- Angularjs学习笔记(二)----模块
一.定义 如何将全局定义的控制器模块化 先看下全局定义的控制器 var HelloCtrl=function($scope){ $scope.name='World'; } 模块化后代码 angula ...
- Webpack - CommonJs & AMD 模块打包器
Webpack 是一个 CommonJs & AMD 模块打包器.可以把你的 JavaScript 代码分离为多个包,在需要的时候进行加载,支持预处理文件,例如 json, jade, cof ...
- JavaScript AMD 模块加载器原理与实现
关于前端模块化,玉伯在其博文 前端模块化开发的价值 中有论述,有兴趣的同学可以去阅读一下. 1. 模块加载器 模块加载器目前比较流行的有 Requirejs 和 Seajs.前者遵循 AMD规范,后者 ...
- 一个简单的AMD模块加载器
一个简单的AMD模块加载器 参考 https://github.com/JsAaron/NodeJs-Demo/tree/master/require PS Aaron大大的比我的完整 PS 这不是一 ...
- JAVA9模块化详解(二)——模块的使用
JAVA9模块化详解(二)--模块的使用 二.模块的使用 各自的模块可以在模块工件中定义,要么就是在编译期或者运行期嵌入的环境中.为了提供可靠的配置和强健的封装性,在分块的模块系统中利用他们,必须确定 ...
- Python进阶(十二)----re模块
Python进阶(十二)----re模块 一丶re模块 re模块是python将正则表达式封装之后的一个模块.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引擎执行. #正则表达式: ...
- web服务器专题:tomcat(二)模块组件与server.xml 配置文件
web服务器专题:tomcat(二)模块组件与server.xml 配置文件 回顾: Web服务器专题:tomcat(一) 基础模块 一个Server.xml的实例 <?xml version= ...
随机推荐
- Hibernate映射类型对照表
Hibernate映射类型对照表 java类型 Hibernate映射类型 SQL类型 java.math.BigDecimal big_decimal numeric byte[] binary ...
- 【JQuery NoviceToNinja系列】目录
[JQuery NoviceToNinja系列]目录 [JQuery NoviceToNinja系列]01 开篇 Html页面设计和布局
- ajax 技术和原理分析
ajax所包含的技术 大家都知道ajax并非一种新的技术,而是几种原有技术的结合体.它由下列技术组合而成. 1.使用CSS和XHTML来表示. 2. 使用DOM模型来交互和动态显示. 3.使用XMLH ...
- Sqli-labs less 45
Less-45 同样的,45关与43关的payload是一样的,只不过45关依旧没有报错信息. 登录 username:admin Password:c');create table less45 l ...
- explicit构造函数的作用
explicit构造函数是用来防止隐式转换的.请看下面的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
- 单例模式及C++实现
单例模式及C++实现代码 C++中的单例模式http://blog.csdn.net/hackbuteer1/article/details/7460019
- java 如何从配置文件(.properties)中读取内容
1.如何创建.properties文件 很简单,建立一个txt文件,并把后缀改成.properties即可 2.将.properties文件拷入src的根目录下 3..properties文件内容格式 ...
- 编程实现Linux下的ls -l
头文件 #ifndef __FUNC_H__ #define __FUNC_H__ #include <stdio.h> #include <stdlib.h> #includ ...
- spring_150806_hibernate_non_transaction
添加hibernate的相关jar包! 实体类: package com.spring.model; import javax.persistence.Entity; import javax.per ...
- GetWindowText和GetDlgItemText的区别
二者使用方法相同,入口点不一样. 举例: CString str; /* if (GetDlgItem(IDC_Number1)->GetWindowText(str),str==" ...