Created
May 25, 2016 20:00
-
-
Save Klortho/b2d3cfed3b8334db83e5d3aaf452ddcd to your computer and use it in GitHub Desktop.
Circular object reference in JavaScript without mutation
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
const Node = function(node) { | |
this.other = (typeof node === 'undefined') ? new Node(this) : node; | |
}; | |
console.log(new Node()); //=> { other: { other: [Circular] } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But I hate that assignment statement -- still a whole lotta mutating going on. This, for example, does not work: