//主程序
var http = require("http");
var otherfun = require("./models/otherfuns.js"); //导入外部模块
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); //协议头
if(request.url !== "/favicon.ico") { //清除第二次访问
fun1(response); //调用内部函数
otherfun.fun2(response); //调用外部函数
otherfun.fun3(response);
response.end(""); //协议尾
}
}).listen(8000);
console.log("Server running at http://127.0.0.1:8000/");
function fun1(res) {
console.log("fun1");
res.write("hello,我是fun1");
}
//外部模块
module.exports = {
fun2: function (res) {
console.log("fun2");
res.write("hello,我是fun2");
},
fun3: function (res) {
console.log("fun3");
res.write("hello,我是fun3");
}
};
函数调用
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 我们在写类的构造函数的时候, 有时候一个构造函数可以完成另一个构造函数中的一部分内容, 这时候我们就希望调用另一...