模塊系統
原生模塊加載的優先級僅次於文件模塊緩存的優先級
假如,你文件目錄下有個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();