嘿,我的javascript文件中有三个函数,比如这个
token.js
const function1 = async (token) => {
.....
};
const function2 = async(token, permission) => {
// I want to call function1 here like
function1(token);
};
module.exports = { function1, function2 }
在function2
我想调用函数,它给了我一个错误function1 is not a function
有谁知道如何解决这个问题?
答案 0 :(得分:2)
应该有效。检查一下:working functions
'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');
答案 1 :(得分:0)
我认为问题在于导入/导出函数的方式: 我稍微改变了你的代码并且它有效:
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')
查看此plunk
答案 2 :(得分:0)
以下是将功能1从说file1.js
到另一个另一个JS文件中的功能2 –说file2.js
的解决方案
file1.js
const function1 = async (token) => {
.....
};
export { function1 }
内部
file2.js
import { function1 } from './src/utils/file1'
{
...other stuff
function1(token);
}