如何在 For 循环的末尾添加条件?
例子:
if (state) {
for (var i = 0, l = $imageLength; i < l; i++) {
if ($images[i].url === state) {
rGallery.init(i);
break;
}
}
/* Need to add here: if NOT in loop... blah*/
} else {
rGallery.init();
}
旁注,也可以改进逻辑以避免它... if (state has a match in the loop) init(i) else init()