【发布时间】:2010-04-13 07:54:29
【问题描述】:
我正在使用 Dojo 并使用 Mastering Dojo 中描述的“模块模式”。就我所见,这种模式是一种通用且广泛使用的 JavaScript 模式。我的问题是:我们如何调试我们的模块?
到目前为止,我还无法说服 Firebug 向我展示我的模块的来源。 Firebug 似乎只显示了用于执行工厂方法的 dojo eval 语句。因此,我无法单步执行我的模块源代码。我尝试在我的模块代码中添加“调试器”语句,Firebug 似乎正确停止,但没有显示源代码。
下面是人为的示例代码。这只是一个足够复杂的例子,使调试的需求变得合理,它并不是有用的代码。
页面
<!--
Experiments with Debugging
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>console me</title>
<style type="text/css">
@import "../dojoroot/dojo/resources/dojo.css";
@import "../dojoroot/dijit/themes/tundra/tundra.css";
@import "edf.css";
</style>
<script type="text/javascript" src="../dojoroot/dojo/dojo.js">
</script>
<script type="text/javascript" >
dojo.registerModulePath("mytest", "../../mytest");
dojo.require("mytest.example");
dojo.addOnLoad(function(){
mytest.example.greet();
});
</script>
</head>
<body class="tundra">
<div id="bulletin">
<p>Just Testing</p>
</div>
</body>
</html>
<!-- END: snip1 -->
我要调试的java脚本
dojo.provide("mytest.example");
dojo.require("dijit.layout.ContentPane");
/**
* define module
*/
(function(){
//define the main program functions...
var example= mytest.example;
example.greet= function(args) {
var bulletin = dojo.byId("bulletin");
console.log("bulletin:" + bulletin);
if ( bulletin) {
var content = new dijit.layout.ContentPane({
id: "dummy",
region: "center"
});
content.setContent('Greetings!');
dojo._destroyElement(bulletin);
dojo.place(content.domNode, dojo.body(), "first");
console.log("greeting done");
} else {
console.error("no bulletin board");
}
}
})();
【问题讨论】:
标签: javascript debugging dojo