我正在使用Dojo並使用Mastering Dojo中描述的「模塊模式」。就我所見,這種模式是一種廣泛使用的JavaScript模式。我的問題是:我們如何調試我們的模塊?JavaScript/Dojo模塊模式 - 如何調試?
到目前爲止,我還沒有能夠說服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");
}
}
})();
debugAtAllCosts在FF和WebKit上通常不再需要,因爲我的回答中提到的原因 – peller 2010-04-13 17:19:47
我只能說沒有這裏顯示的djconfigs,調試器顯示「eval」行而不是eval-ed代碼,步進是沒有用。我用djconfig顯示完整的源代碼是可見的,我可以很好地進行分析。 – djna 2010-04-14 05:36:46
在Chrome中,我發現我能夠調試我的模塊的源代碼,但不能在Firebug(1.8)中使用,所以這個答案相當省時,謝謝。 – mydoghasworms 2011-10-19 07:50:11