Skip to content

Instantly share code, notes, and snippets.

@RobinStamer
Created October 20, 2012 22:45
Show Gist options
  • Select an option

  • Save RobinStamer/3925095 to your computer and use it in GitHub Desktop.

Select an option

Save RobinStamer/3925095 to your computer and use it in GitHub Desktop.
> a = {}; b = {next: a}; c = {next: b}; d = {next:c}; a.next = d
{ next: { next: { next: [Object] } } }
> a
{ next: { next: { next: [Object] } } }
> JSON.stringify(a)
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at repl:1:7
at REPLServer.self.eval (repl.js:111:21)
at Interface.<anonymous> (repl.js:250:12)
at Interface.EventEmitter.emit (events.js:88:17)
at Interface._onLine (readline.js:199:10)
at Interface._line (readline.js:517:8)
at Interface._ttyWrite (readline.js:735:14)
at ReadStream.onkeypress (readline.js:98:10)
at ReadStream.EventEmitter.emit (events.js:115:20)
> function del(x) { delete x; console.log(++del.count); }; del.count = 0
0
> entry = c; cur = entry.next; while (cur != entry) { next = cur.next; del(cur); cur = next } del(entry)
1
2
3
4
undefined
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment