1.node 在node中 进行包与包之间函数的调用 module.exports

本文参考学习了廖雪峰的大作 模块

但是廖的文章只模块只有一个函数,在此演示一个模块中有两个函数,在另外一个函数中是如何去调用的

//hello.js包中的内容
'use strict'; var s='hello baby'; function greet(name){ console.log(s+','+name+'!'); } function call(name){ console.log('喂,你好'+','+name+'!'); } //下面为关键 module.exports={ greet:greet, call:call };

下面为调用hello.js的另外一个包main.js中的代码

'use strict';

var greet=require('./hello').greet;
var phonecall=require('./hello').call;

var s='I m man,your man';

greet(s);
phonecall(s);

执行node 显示如下:

 看到两个在廖雪峰网址中的关于exports 和module.ports的不错的留言 粘贴如下:

留言1----------------------------------------------------------------------------------------------------------------------

留言2----------------------------------------------------------------------------------------------------------------------

 

posted @ 2018-07-19 16:04  当年在远方  阅读(277)  评论(0编辑  收藏  举报