Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据其在节点中的类型包括来自帮助器的函数_Javascript_Node.js - Fatal编程技术网

Javascript 根据其在节点中的类型包括来自帮助器的函数

Javascript 根据其在节点中的类型包括来自帮助器的函数,javascript,node.js,Javascript,Node.js,我有一个模块助手,它包含内容、用户和类似文件,用于定义路由器中使用的不同助手。这是路由器: router.js var helper = require("./helper"); function index(response) { response.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); response.write("<something>"); response.end

我有一个模块助手,它包含内容、用户和类似文件,用于定义路由器中使用的不同助手。这是路由器:

router.js

var helper = require("./helper");

function index(response) {
    response.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
    response.write("<something>");
    response.end();
}
var content = require("./content");
var user = require("./user");
var post = require("./post");
...
现在,我想在路由器中执行以下操作:

response.writeHead(200, Content.html());
替换长散列。在没有类的情况下,有没有一种简单的方法可以做到这一点(因为如果我想使用helper中的一些函数,我总是需要初始化对象)?我知道我能做到

exports.html = content.html;

而使用html(),但我感兴趣的是,是否有这样的方法?

以大写字母开头的标识符(如
内容
)应该只用于类

为什么不去掉
helper/index.js
,直接导入所需的模块

const content = require('./helper/content')

function index(response) {
  response.writeHead(200, content.html());
  response.write("<something>");
  response.end();
}
const content=require('./helper/content')
功能索引(响应){
writeHead(200,content.html());
回答。写(“”);
response.end();
}

我不明白你的问题。简单地导出它有什么问题?@Gothdo-Ya,它看起来有点复杂-因为如果我在某个地方有同名的函数,我需要更改它的名称。通过这种方式,我可以同时编写Content.html()和Post.html()。你知道,类似于其他语言中的名称空间。