現在、私は問題を引き起こしているかなり機能不全のJavascriptプログラムを持っています。しかし、それは私は理解していない1つのエラースロー:あなたはおそらく推測できるように私は、何をしようとしているTypeError: 'undefined'はオブジェクトではありません
TypeError: 'undefined' is not an object (evaluating 'sub.from.length')
を、sub
辞書内の特定の「from
」配列のlength
をチェックしています。ここでsource code for the entire functionだし、ここで私は、エラーを引き起こしていると思わループのコードです:
console.log(afcHelper_ffuSubmissions.length); // just for debugging, returns the correct number
for (var i = 0; i < afcHelper_ffuSubmissions.length; i++) { // this whole section works fine
var sub = afcHelper_ffuSubmissions[i];
//console.log("THIS IS BROKEN DOWN BY LINK",afcHelper_Submissions[i]);
if (pagetext.indexOf(afcHelper_ffuSections[sub.section]) == -1) {
// Someone has modified the section in the mean time. Skip.
document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': Cannot find section. Perhaps it was modified in the mean time?</li>';
continue;
}
var text = afcHelper_ffuSections[sub.section];
var startindex = pagetext.indexOf(afcHelper_ffuSections[sub.section]);
var endindex = startindex + text.length;
console.log(sub);
if (typeof(sub.from) != 'undefined' && sub.from.length > 0) { // ** problem spot?? this is the code i recently added.
for (var i = 0; i < sub.from.length; i++) {
mainid = sub.from[i]['id'];
var sub = afcHelper_Submissions[mainid]; // and then it goes on from here...
任意のアイデアは素晴らしいことです。率直に言って、私はなぜ私がすでに明示的に(typeof(sub.from)
)のタイプをチェックしたかについてTypeError
を得ているのを見ることができません...
FirebugやChromeの内蔵デバッガなどのJavascriptデバッガを使用します。そこにブレークポイントを置き、変数を調べることができます。 –
サンプルデータはありますか? – loganfsmyth
おそらく、sub.fromはnullです: 'typeof(null)!=" undefined "; // = true' – HMR