WeakMap better than Private Symbols? (was: direct_proxies "problem")
Kris Kowal
kris.kowal at cixar.com
Thu Jan 10 09:20:06 PST 2013
As an aside, Irakli Gozashvili and I independently realized that you
could use a WeakMap for parallel objects with inheritance. Very
similar to Brendan’s createStorage, we put together a parallel
universe constructor.
function Parallel(root) {
var parallel = new WeakMap();
root = root || null;
function get(object) {
if (!parallel.has(object)) {
parallel.set(object,
Object.create(get(Object.getPrototypeOf(object))));
}
return parallel.get(object);
}
return get;
}
Irakli’s was a Namespace constructor that appeared somewhere in the
Mozilla Add-on toolkit, but the links have gone stale.
Kris Kowal
More information about the es-discuss
mailing list