我是一个dojo新手,当我使用dojo时,我被dojo require 块弄糊涂了,这里我给出三种写dojo的方法,哪一种最好?编程风格1,你可以在dojo教程中看到这个,但我不喜欢这种风格,我喜欢将事件添加为html标签属性<div onclick='test()'></div>
,在这种风格下,我无法访问函数test1()
<script>
require(["dojo/query", "dojo/dom","dojo/domReady!"], function(query, dom){
function test1(){}
function test2(){}
//...other functions
});
</script>
编程风格2,定义一次require,然后在funciton中使用
<script>
require(["dojo/dom"]);
function test1(){
var dom=require("dojo/dom");
//do something with dom
}
function test2(){
var dom=require("dojo/dom");
//do something with dom
}
</script>
编程风格3,函数内部的require块
<script>
function mytest(){
require(["dojo/query", "dojo/dom"], function(dom){
//do something with dom
})
}
function mytest2(){
require(["dojo/query", "dojo/dom"], function(dom){
//do something with dom
})
}
</script>