在Node.js中,process.hrtime是这样的Object

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()!

07-26 08:28