在 Node.js 中,process.hrtime 是这样的对象
hrtime: { [Function: hrtime] bigint: [Function] },
(在 pcoress 对象中)
hrtime 可以由 process.hrtime()
执行,并具有键 bigint
作为由 process.hrtime.bigint()
执行的函数。
我想知道hrtime
怎么可能同时是一个函数和对象。
我尝试在对象中包含匿名函数,但失败了。
我怎样才能做到?
process {
title: 'node',
version: 'v10.16.3',
...
hrtime: { [Function: hrtime] bigint: [Function] },
...
}
最佳答案
您可以像为任何对象分配属性一样为函数分配属性。
function x() {
console.log("You have successfully called x()!");
}
function y() {
console.log("Hello, this is y()!");
}
x.y = y;
x();
x.y();
打印出来
You have successfully called x()!
Hello, this is y()!
关于node.js - Node.js 中对象如何具有匿名函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57754889/