如果我有两个文件
include_me.js
我想将参数传递给脚本module.exports = function(arg1) {
// Script code - does something with arg1
};
,然后运行它。
我能想到的最好的是:
include_me.jsvar arg_to_be_passed = { //..... };
var script = require('include_me');
script(arg_to_be_passed);
main.js
SELECT DISTINCT u.id
FROM User u
WHERE
(
SELECT COUNT(*)
FROM
( SELECT TOP 5 *
FROM Event e
ORDER BY EventDate(DESC)
WHERE e.UserID = u.Id) x
WHERE u.[Type] = 1 OR u.[Type] = 2
) = 5
这是正确的还是有更简单的方法?
答案 0 :(得分:1)
你是对的,但你可以让它更漂亮:
var arg_to_be_passed = { //..... };
var script = require('include_me')(arg_to_be_passed);
这样你就可以保存一行,因为你还是需要传递参数。