Last active
October 25, 2016 04:14
-
-
Save dg3feiko/23b13ba62778e3f52acda5d4c16c0d63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const util = require("util"); | |
let foo = {}; | |
let bar = {}; | |
foo.ref = bar; | |
bar.ref = foo; | |
console.log(JSON.stringify(foo)); | |
//TypeError: Converting circular structure to JSON | |
console.log(util.inspect(foo, { showHidden: true, depth: null })); | |
//{ ref: { ref: [Circular] } } | |
/////////////////////// | |
let foo = { | |
}; | |
let bar = function () { | |
this.ref = foo; | |
}; | |
foo.ref = bar; | |
console.log(JSON.stringify(foo)); | |
//{} | |
console.log(util.inspect(foo, { showHidden: true, depth: null })); | |
//{ ref: | |
// { [Function] | |
// [length]: 0, | |
// [name]: '', | |
// [prototype]: { [constructor]: [Circular] } } } | |
'use strict'; | |
const util = require("util"); | |
const EventEmitter = require('events'); | |
class Foo extends EventEmitter{} | |
let foo = new Foo(); | |
foo.on("bar", function barHandler(){ | |
foo.bar = "bar"; | |
}) | |
console.log(JSON.stringify(foo)); | |
//{"domain":null,"_events":{},"_eventsCount":1} | |
console.log(util.inspect(foo, { showHidden: true, depth: null })); | |
// Foo { | |
// domain: null, | |
// _events: | |
// { bar: | |
// { [Function: barHandler] | |
// [length]: 0, | |
// [name]: 'barHandler', | |
// [prototype]: barHandler { [constructor]: [Circular] } } }, | |
// _eventsCount: 1, | |
// _maxListeners: undefined } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment