Created
December 8, 2023 10:11
-
-
Save KMahoney/99d4718ac897b8c42353301eb8114234 to your computer and use it in GitHub Desktop.
This was an annoying bug to find
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
class Bar { | |
constructor(public foo: Foo) {} | |
} | |
class Foo { | |
private cachedBar: Bar | null = null; | |
getBar() { | |
if (this.cachedBar !== null) return this.cachedBar; | |
this.cachedBar = new Bar(this); | |
return this.cachedBar; | |
} | |
} | |
function makeFoo() { | |
const baseFoo = new Foo(); | |
// extend with some convenient properties | |
return Object.create(baseFoo, { bar: { value: baseFoo.getBar() } }); | |
} | |
const foo = makeFoo(); | |
console.log(foo === foo.getBar().foo); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment