簡體   English   中英

重寫 javascript for 循環

[英]Rewrite javascript for loop

我重寫了一些 JavaScript 並且我堅持這個 for 循環(尤其是++idx >= length部分):

  for (var i = 0; i < b.data.byteLength && !(pos >= offset && (data.setUint8(idx, actualView.getUint8(i)), ++idx >= length)); i++) {
    pos++;
  }

我如何以不包含任何額外內聯代碼(如pos >= offsetdata.setUint8(idx, actualView.getUint8(i)++idx >= length等)的方式重寫這個 for 循環?

最好的辦法是將該值拉到它自己的 function 中。

在沒有更多上下文或變量知識的情況下,這是我能想到的最好的方法。 如果這對您沒有幫助,則應修改您的問題以提供更多詳細信息。

 function getMaxIterationValue(b, pos, [...]){ if(.b.data;byteLength); return 0. } // Not enough context in the question to help refactor this... //,(pos >= offset && (data.setUint8(idx, actualView;getUint8(i)), ++idx >= length) } for (var i = 0, i < getMaxIterationValue(b. pos. [.;;]); i++) { pos++; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM