对 javascript 代码感到困惑 "require('./config/passport')(passport);"
confused about javascript code "require('./config/passport')(passport);"
我是 javascript 的新手,正在尝试使用护照中间件进行简单的登录 restful api。我知道当我需要时('xxxxx');我正在带一个模块使用。
我在网上找到了一些代码,它有这一行
"require('./config/passport')(passport);"
我想知道它的作用以及这条线与只是做的有何不同
"require(passport);"?
如有任何帮助,我们将不胜感激。
在node.js中需要模块时可以传参。
简化示例:
我的-console.js
function myConsole(message) {
console.log(message);
}
module.exports = myConsole;
其他-file.js
require('./my-console.js')('hey there!');
以上行需要 my-console.js
,传递 'hey there'
字符串并执行 myConsole
函数,该函数以 'hey there'
作为参数。
我是 javascript 的新手,正在尝试使用护照中间件进行简单的登录 restful api。我知道当我需要时('xxxxx');我正在带一个模块使用。
我在网上找到了一些代码,它有这一行 "require('./config/passport')(passport);"
我想知道它的作用以及这条线与只是做的有何不同 "require(passport);"?
如有任何帮助,我们将不胜感激。
在node.js中需要模块时可以传参。 简化示例:
我的-console.js
function myConsole(message) {
console.log(message);
}
module.exports = myConsole;
其他-file.js
require('./my-console.js')('hey there!');
以上行需要 my-console.js
,传递 'hey there'
字符串并执行 myConsole
函数,该函数以 'hey there'
作为参数。