Created
July 2, 2016 04:48
-
-
Save krisselden/546ec1f872e46d130049c7695931b11e to your computer and use it in GitHub Desktop.
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 metaMap = new WeakMap(); | |
const getPrototypeOf = Object.getPrototypeOf; | |
function peekMeta(obj) { | |
let o = obj; | |
let m; | |
while (o) { | |
m = metaMap.get(o); | |
if (m) return m; | |
o = getPrototypeOf(o); | |
} | |
} | |
function deleteMeta(obj) { | |
metaMap.set(obj, null); | |
} | |
function setMeta(obj, meta) { | |
metaMap.set(obj, meta); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment