Reputation: 48
in Node.js, process.hrtime is Object like that
hrtime: { [Function: hrtime] bigint: [Function] },
(in pcoress object)
hrtime can be executed by process.hrtime()
and has key bigint
as a function that executed by process.hrtime.bigint()
.
i wonder how it possible hrtime
is a function and object at the same time.
i tried to include anonymous function in object, but failed.
how can i make it?
process {
title: 'node',
version: 'v10.16.3',
...
hrtime: { [Function: hrtime] bigint: [Function] },
...
}
Upvotes: 1
Views: 263
Reputation: 169338
You can assign properties on functions like you can onto any object.
function x() {
console.log("You have successfully called x()!");
}
function y() {
console.log("Hello, this is y()!");
}
x.y = y;
x();
x.y();
prints out
You have successfully called x()!
Hello, this is y()!
Upvotes: 2