我想迭代并调用与" os"
相关联的所有成员函数var os = require('os');
var keye = Object.keys(os);
keye.forEach(f => os.f());
原型:
{ endianness: [Function: getEndianness],
hostname: [Function: getHostname],
loadavg: [Function: getLoadAvg],
uptime: [Function: getUptime],
freemem: [Function: getFreeMem],
totalmem: [Function: getTotalMem],
cpus: [Function: getCPUs],
type: [Function: getOSType],
release: [Function: getOSRelease],
networkInterfaces: [Function: getInterfaceAddresses],
arch: [Function],
platform: [Function],
tmpdir: [Function],
tmpDir: [Function],
getNetworkInterfaces: [Function: deprecated],
EOL: '\r\n' }
答案 0 :(得分:0)
你需要这样的东西:
Object.keys(os).forEach(function (key) {
if (typeof os[key] === 'function') {
console.log(key, os[key]());
}
});