[英]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.