javascript - 节点js需要执行功能
问题描述
我无法执行该功能。当我node app.js
在终端运行时,我得到[Function: hi]
.
我有两个文件
应用程序.js
var show = require('./code');
console.log(show.hi);
代码.js
function hi() {
console.log('I am inside function Hi');
}
module.exports.hi = hi;
如果我会做这样的事情,console.log(show.hi())
那么我会得到
I am inside function Hi
undefined
解决方案
因为您没有调用该函数。
像这样称呼它
show.hi();
你得到 undefined 因为你的hi
函数什么都不返回。删除console.log
我的意思是只执行该功能show.hi()
总之console.log(show.hi);
应该只是 show.hi()
推荐阅读
- sql - 将 SQL CTE 表达式转换为普通子查询
- c - 使用不兼容类型调用的没有原型的函数
- javascript - 如何将 OpenCV 图像分配给 QtWebkit 图像元素?
- c++ - Boost::Spirit 表达式解析器,带有定义的函数
- jquery - jQuery中的toggleClass跳过css规则
- javascript - Vuejs用参数调用其他组件的方法
- python - 分类算法适用于高维数据集?
- amazon-web-services - kops ssh 公钥权限被拒绝
- javascript - p5.js 中的角碰撞角度
- java - Java 9 服务 - 遍历提供者类?