你應該能夠頁碼的數組傳遞給函數。 我接過一看scissors source code,他們似乎採取實際的參數自理:
/**
* Creates a copy of the pages with the given numbers
* @param {(...Number|Array)} Page number, either as an array or as arguments
* @return {Command} A chainable Command instance
*/
Command.prototype.pages = function() {
var args = (Array.isArray(arguments[0])) ?
arguments[0] : Array.prototype.slice.call(arguments);
var cmd = this._copy();
return cmd._push([
'pdftk', cmd._input(),
'cat'].concat(args.map(Number), [
'output', '-'
]));
};
您可以通過將被組合成陣列Array.prototype.slice
多個參數或只是通過將用於數組直。
var scissors = require('scissors');
var pages = [];
/* collect desired pages */
pages.push(23);
pages.push(42);
pages.push(1337);
var pdf = scissors('in.pdf').pages(pages);
還有的[ES6傳播語法(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator) –