繁体   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