Skip to content

Instantly share code, notes, and snippets.

@modernserf
Last active December 11, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modernserf/d48baaaa0456be92e03e57690da1bfec to your computer and use it in GitHub Desktop.
Save modernserf/d48baaaa0456be92e03e57690da1bfec to your computer and use it in GitHub Desktop.
Notes for "The Tyranny of Triple-Equals"
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
}
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