dojo/declare()
Defining a Class
dojo官网对于这个部分写的不是很清晰,刚入门的时候很容易不知道各个地方是什么含义,所以写了这篇
参考地址:https://dojotoolkit.org/reference-guide/1.10/dojo/_base/declare.html
定义dojo的类
define(["dojo/_base/declare(这写的是这个类里用的其他的类的地址)"], function(declare(这里写前面的类似于类名)){
return declare(这里写类名下面调用的时候用, {
constructor: function(name, age, residence(类所需的参数值)){
this.name = name;
this.age = age;
this.residence = residence;
}
});
});
Using the class:
调用
require(["my/Person(这里写类的地址,一般来说可以把类的文件夹写成固定的)"], function(Person(和上面的差不多)){
var folk = new Person("phiggins", 42, "Tennessee"这是参数值);//调用的时候使用
});
dojoConfig
上面那个文件夹固定的方法
var dojoConfig = {
packages:[{
async: true,//这个参数一定要设置,必须要设置true
parseOnLoad: true,
name:'myapi',
//location: location.pathname.replace(/\/[^/]*$/, '') + 'scripts'//文件夹地址
location: origin + 'JS路径'
}]
};
其中地址的位置
var origin = 'http://' + location.host; /*根目录*/