如何调用数组中的所有javascript成员函数?[node.js]
我想遍历并调用与相关联的所有成员函数“os” 原型:如何调用数组中的所有javascript成员函数?[node.js],node.js,object,iteration,Node.js,Object,Iteration,我想遍历并调用与相关联的所有成员函数“os” 原型: 你需要这样的东西: Object.keys(os).forEach(function (key) { if (typeof os[key] === 'function') { console.log(key, os[key]()); } }); 你能回答这个问题吗? { endianness: [Function: getEndianness], hostname: [Function: getHostn
你需要这样的东西:
Object.keys(os).forEach(function (key) {
if (typeof os[key] === 'function') {
console.log(key, os[key]());
}
});
你能回答这个问题吗?
{ 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' }
Object.keys(os).forEach(function (key) {
if (typeof os[key] === 'function') {
console.log(key, os[key]());
}
});