Dojo加载自定义对象
2016-04-11 13:09
387 查看
Dojo加载自定义对象的一种方法
定义有如下对象:
./js/com/WebGIS/Graphics/Shape.js中:
define(['dojo/_base/declare'], function (declare) {
return declare(
null,
{
color: 0,
setColor: function (color) {
this.color = color;
}
});
});
./js/com/WebGIS/Graphics/Circle.js中:
define(["dojo/_base/declare", "com/WebGIS/Graphics/Shape"], function (declare, Shape) {
return declare(
Shape,
{
constructor: function (radius) {
this.radius = radius | this.setRadius;
},
setRadius: function (radius) {
this.radius = radius;
},
area: function () {
return Math.PI * this.radius * this.radius;
}
});
});
加载文件时:
<script src="http://localhost:8080/dojoroot/dojo/dojo.js"></script> //加载dojo
<script>
(function () {
var currentPath = location.href.substring(0, location.href.lastIndexOf("\/"));
require({ //定义加载当前块环境需要的包名称定义
packages: [{ name: "com", location: currentPath + "/js/com" }]
})
require(["com/WebGIS/Graphics/Circle", "dojo/domReady!"], function (Circle) {
var circle = new Circle(4);
console.log(circle.area());
console.log(circle.color);
});
}());
</script>
定义有如下对象:
./js/com/WebGIS/Graphics/Shape.js中:
define(['dojo/_base/declare'], function (declare) {
return declare(
null,
{
color: 0,
setColor: function (color) {
this.color = color;
}
});
});
./js/com/WebGIS/Graphics/Circle.js中:
define(["dojo/_base/declare", "com/WebGIS/Graphics/Shape"], function (declare, Shape) {
return declare(
Shape,
{
constructor: function (radius) {
this.radius = radius | this.setRadius;
},
setRadius: function (radius) {
this.radius = radius;
},
area: function () {
return Math.PI * this.radius * this.radius;
}
});
});
加载文件时:
<script src="http://localhost:8080/dojoroot/dojo/dojo.js"></script> //加载dojo
<script>
(function () {
var currentPath = location.href.substring(0, location.href.lastIndexOf("\/"));
require({ //定义加载当前块环境需要的包名称定义
packages: [{ name: "com", location: currentPath + "/js/com" }]
})
require(["com/WebGIS/Graphics/Circle", "dojo/domReady!"], function (Circle) {
var circle = new Circle(4);
console.log(circle.area());
console.log(circle.color);
});
}());
</script>
相关文章推荐
- ZOJ 3785-What day is that day?-数论(费马小定理) / 打表找规律
- 欢迎使用CSDN-markdown编辑器
- Mac怎么不能拷贝文件到U盘
- TCP协议——客户端与服务端一问一答聊天
- Ubuntu 安装vsftp软件(已测试)
- 修改系统时间
- 跋涉不止(37)
- 信息交流平台专业介绍模块的分析(UML)与设计
- cf590A. Median Smoothing
- xUtils 中的HttpUtils全面注释
- Ubuntu安装opencv with cuda
- java 笔录
- UITableViewCell在重用ID时为何加上Static关键字
- html5 笔录
- Maven将项目部署到Tomcat-报错:java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
- 简单C三道!
- 撰写英文SCI文章的技巧
- shell变量赋值 不能有空格的原因
- 【机器学习】多元高斯分布下的贝叶斯分类感知器
- PopupWindow弹出框且背景变暗