require('module1') // 沒有定義命名,如何使用?var module2 = require('module2') // 可以使用module2調(diào)用模塊里的函數(shù)批量導(dǎo)入模塊var models_path = __dirname + '/app/models'var walk = function(path) {
fs
.readdirSync(path)
.forEach(function(file) { var newPath = path + '/' + file
var stat = fs.statSync(newPath) if (stat.isFile()) { if (/(.*)\.(js|coffee)/.test(file)) {
require(newPath)
}
} else if (stat.isDirectory()) {
walk(newPath)
}
})
}
walk(models_path)這里導(dǎo)入的模塊如何調(diào)用模塊里的方法呢?如果這樣無法使用模塊那么這樣可以批量導(dǎo)入并可以使用模塊?
node中require導(dǎo)入模塊,但是沒有定義命名,如何使用調(diào)用模塊里的函數(shù)
絕地?zé)o雙
2018-09-07 09:21:50