1
私は自分自身が以下のようなコードをたくさん書いていると思っています。それは、コード作成プロセス全体をより苦痛にさせて、そうするべきだと感じるようにします。そこに良いアプローチはありますか?サファリのためのJavaScriptを開発中 - 死のボールを防ぐ
function drawArrowsInDocument (document, boxes, context) {
console.log ("drawArrowsInDocument");
var body = document.body;
if (!body) {
console.log ("no body!");
return;
}
var rectangles = rectanglesWithBoxes(boxes);
if (!rectangles) {
console.log ("no rectangles!");
return;
}
var descendants = body.childNodes;
if (!descendants) {
console.log ("no descendants");
return;
}
var length = descendants.length;
if (length>10000) {
console.log ("too many descendants");
return;
}
// now I know my variables actually exist, and I can do something with them.
ここがクラッシュしたときの表示です。その時点で私ができることは、Safariを再起動し、問題を見つけるためにif文をいくつか追加することだけです。代わりにconsole.logの使用assertions
私はクロームが少なく不安定で、ほぼ正確に同じエンジンを見つけます。 'throw'を使っていつでもスクリプトを停止することができます。無限ループでは死の球が最も一般的ですので、それらのループを再考してください。 – David