函数调用

2016-09-27  本文已影响0人  zz张哲
//主程序
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");
    }
};
上一篇 下一篇

猜你喜欢

热点阅读