模块系统
原生模块加载的优先级仅次于文件模块缓存的优先级
假如,你文件目录下有个http/http.js/http.node/http.json的文件夹
require('http')也会从原生加载
8、
require方法接受以下传参
a、http、fs、path等,原生模块。
b、./mod或../mod,相对路径的文件模块。
c、/pathtomodule/mod,绝对路径的文件模块。
d、mod,非原生模块的文件模块。
//16.1.11.js
function Hello(){
var name;
this.setName = function(val) {
name = val;
}
this.sayHello = function() {
console.log("Hello: " + name);
}
}
module.exports = Hello;
//16.1.11_1.js
var Hello = require('./16.1.11.js');
var hello = new Hello();
hello.setName('DoubleStar')
hello.sayHello();