簡體   English   中英

遞歸函數不增加自己的參數

[英]Recursive function not incremeanting its own parameter

 var documentURLs = ["maca.pdf", "maca2.pdf"] function printDocuments(index){ if(index > documentURLs.length){ return; } else { printJS({ printable: documentURLs[index], type: 'pdf', onPrintDialogClose: function () { console.log(index); printDocuments(index++) } }) } }
 <button type="button" onclick="printDocuments(0)">Print</button>

這不會增加索引,始終打印第一個文檔並且不會停止

它的行為與其應有的完全一樣。 如果你想用下一個索引調用printDocuments ,你應該使用printDocument(++index)或只使用printDocument(index+1) ,因為它是最容易混淆的。 i++返回的電流值i ,然后添加1 ++i第一加1點,並返回該增加的值(因此i+1 )。

暫無
暫無

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

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