var bookmark_iterator = page_element.firstChild;
do {
// start insertion
if (bookmark_iterator === null) {
page_element.appendChild(div_el);
break;
}
// middle insertion
if (div_el.id < bookmark_iterator.id) {
page_element.insertBefore(div_el, bookmark_iterator);
break;
}
// end insertion
if (bookmark_iterator === page_element.lastChild) {
// if null will insert at the end per reference
bookmark_iterator = null;
page_element.insertBefore(div_el, bookmark_iterator);
break;
}
// increment loop
bookmark_iterator = bookmark_iterator.nextSibling;
} while (bookmark_iterator !== null);
问题是http://jslint.com抛出错误:
line 643 character 19
Unexpected 'else' after disruption.
因为我的 if/else 结构中有一个 break 语句。
这让我觉得我把一个简单的字母插入太复杂了。有没有更简单或更好的方法来编写它以使其通过 jslint?