It would really help debugging if all environments just logged the same content consistently! I am having a problem being able to just log the correct contents across different IDEs and browsers.
After reading various other posts (e.g. here), I’m trying to simply log the methods of an object. Take this code for example from this CodePen:
class User {
constructor(name) {
this.name = name;
}
fn() {
return 'fn';
}
fn2() {
return 'fn2';
}
static staticFn() {
return 'static fn'
}
}
const joe = new User('Joe')
console.log(joe)
console.log(joe.fn)
console.log(Object.getPrototypeOf(joe)) // the important part!
The methods fn
and fn2
should at least be logged. If you copy the above code snippet and paste it into chrome’s JS console then it correctly logs everything, particularly the important part (the final log):
However, paste the same code into Safari’s JS console and the important part incorrectly logs as just User {}
, not showing the object’s methods:
Additionally the CodePen’s important part just logs [object Object] {}
:
And VSCode just logs {}
.
So my question is how can you correctly log the methods of an object in all environments? It’s causing a nightmare trying to debug anything as some node code I have only runs in an IDE, unavailable to a browser.
This has come from a bug where I’m fetching an object from a mongo database that strangely doesn’t seem to have any methods despite the object having methods before being inserted into the database.
Any advice or debugging tips would be greatly appreciated, thank you.