[英]How to call arrow function in another arrow function in nodejs
嘿,我的 javascript 文件中有这样的三个函数
令牌.js
const function1 = async (token) => {
.....
};
const function2 = async(token, permission) => {
// I want to call function1 here like
function1(token);
};
module.exports = { function1, function2 }
在function2
我想调用 function 它给了我一个错误function1 is not a function
有谁知道如何解决这个问题?
它应该工作。 检查这个:工作功能
'use strict'; const function1 = async (token) => { console.log(token); }; const function2 = async(token, permission) => { // I want to call function1 here like function1(token); }; function2('apple','ball');
我认为问题在于您导入/导出函数的方式:我稍微更改了您的代码,它可以工作:
const function1 = async (token) => {
console.log(token)
};
const function2 = async (token) => {
// I want to call function1 here like
//console.log(token)
function1(token);
};
export const f= { function1, function2 }
和使用该函数的代码:
import {f} from './funcs.ts'
f.function2('ooo')
看看这个笨蛋
以下是将file1.js
function1 使用到另一个不同 JS 文件中的 function2 的解决方案 - 比如file2.js
文件1.js
const function1 = async (token) => {
.....
};
export { function1 }
而里面
文件2.js
import { function1 } from './src/utils/file1'
{
...other stuff
function1(token);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.