Last active
December 11, 2018 17:55
-
-
Save modernserf/d48baaaa0456be92e03e57690da1bfec to your computer and use it in GitHub Desktop.
Notes for "The Tyranny of Triple-Equals"
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
let lookupTable = Immutable.Map({}) | |
export function record (fields) { | |
let key = Immutable.Map(fields) | |
let storedValue = lookupTable.get(key) | |
if (storedValue) { return storedValue } | |
let newValue = Object.freeze({ ...fields }) | |
lookupTable = lookupTable.set(key, newValue) | |
return newValue | |
} |
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 Foo = (() => { | |
const PRIVATE = new WeakMap() | |
return class Foo { | |
value (...args) { | |
if (args.length) { | |
PRIVATE.set(this, args[0]) | |
return this | |
} | |
return PRIVATE.get(this) | |
} | |
} | |
})() | |
let x = new Foo() | |
x.value(1) | |
let y = new Foo() | |
y.value(2) | |
x.value === y.value // => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment