我编写了一个简单的程序,其中编写了一个java脚本函数,如下所示
function add( num1,num2){
return num1 + num2;
}
module.export={
add
}
console.log (add(5,4));
下面给出的是另一个函数index.spec.js,它从index.js导入add函数
const assert = require('assert')
const { add } = require('./index')
console.log(add(5,6))
因此,当我尝试使用 npm commmand 运行 index.spec.js 时,我收到错误“add is not afunction”,如下所示 error
最佳答案
您导出模块的方式错误,请将其更改为
module.exports = { add }; //with the final s
关于javascript - 我得到 x is not a function in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53116646/