0
const TelegramBot= require('./telegram-bot') // It's currently only local.

var bot = new TelegramBot()

console.log(bot)
// This does not print a complete JSON of the object. It misses stuff like 
constructor, method, prototype and super_.

Is there some way or npm module that prints a JSON compatible output of the object?

My only work around so far is console logging it out like this and repeatedly checking the log and printing out another but I think it'll be a lot of easier by having a JSON export and using a JSON online viewer that views like a directory tree.

console.log(`
   TelegramBot:
   > ${Object.getOwnPropertyNames(TelegramBot)}

   TelegramBot.prototype:
   > ${Object.getOwnPropertyNames(TelegramBot.prototype)}

   TelegramBot.prototype.constructor:
   > ${Object.getOwnPropertyNames(TelegramBot.prototype.constructor)}

   TelegramBot.prototype.constructor.super_:
   > ${Object.getOwnPropertyNames(TelegramBot.prototype.constructor.super_)}
`)

I'm aware functions can't be seen with JSON.parse(). I don't mind if they appear as a string like "Anonymous Function()" or "FunctionWithAName()". Or something like this.

I'm doing this since I'm having another go trying to learn prototypes and I've used util.inherits(TelegramBot, EventEmitter) in the TelegramBot object.

To avoid name clashes between TelegramBot methods I've made and the super class of EventEmitter names. I'd like to keep a clear view of the whole object structure. Or do I not have to worry since they use this variable shadowing thing? If I'm correct it checks the object's instance first, then it's prototype. Not sure if EventEmitter prototype checked first or TelegramBot's.

Nova
  • 2,000
  • 3
  • 14
  • 24
  • 1
    Maybe this might help: https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object – madllamas Sep 09 '17 at 04:54
  • Actually works quite well. It's kinda strange though. When I view the new instance of `bot` it shows only public `this` values but not the prototype methods unless I view `TelegramBot` function which I'm guessing is how it works. If it can't find it on bot it checks the original object. Which comes first when it checks prototypes the base or the inherit or are they combined? – Nova Sep 09 '17 at 06:04
  • If you wanna view the prototype of `bot`. try `Object.getPrototypeOf(bot)` instead of `bot`. And sorry i don't get the last question – madllamas Sep 09 '17 at 06:18

0 Answers0