我有一个关于javascript性能更好的问题:
具有:
if (item.items.length > 0) {
for (x = 0; x < item.items.length; x++) {
var childElement = element.items[x];
group.appendChild({
classname: childElement.class_name,
text: childElement.title,
leaf: true
});
}
}
或直接
for (x = 0; x < item.items.length; x++) {
var childElement = element.items[x];
group.appendChild({
classname: childElement.class_name,
text: childElement.title,
leaf: true
});
}
要回答您的问题:if
循环之前不需要。for
循环的定义包括一条if
语句,用于确定循环是否应循环打开。
那将是一个infnit循环:
for (;;;){}
这个也是:
for (var i = 0; true; i++) {}
一般来说:
for (<initialze>; <if statement>; <js do that each loop if you run>) {/*code*/}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句