Answer the question
In order to leave comments, you need to log in
How to display the methods that an instance of a class has in the console in Node.js?
When in the console I output console.log(global); (this is an example, any object can be here), I only see this:
<ref *1> Object [global] {
global: [Circular *1],
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTimeout] {
[Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
},
queueMicrotask: [Function: queueMicrotask],
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
}
}
Answer the question
In order to leave comments, you need to log in
First, log via console.dir with showHidden: true
// Для класса ClassName
console.dir(ClassName.prototype, {showHidden: true});
// Для любого объекта или инстанса класса obj
console.dir(Object.getPrototypeOf(obj), {showHidden: true});
class SomeClass extends Array {}
function collectPrototypesChain(obj) {
const proto = Object.getPrototypeOf(obj);
if(!proto) { return null; }
const {name} = proto.constructor;
return {name, proto, next: collectPrototypesChain(proto)};
}
console.dir(collectPrototypesChain(new SomeClass()), {showHidden: true, depth: 4});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question