17 ms·
var map = Object.create(null); ..will not have any of those properties. Works only in v8 though, AFAIK.
by ypcx 15y ago
var map = Object.create(null);
..will not have any of those properties. Works only in v8 though, AFAIK.
- chc 15y agoI just tested and it looks like it works in SquirrelFish/Nitro and SpiderMonkey as well. Cool trick — I didn't know about that. But I don't think it quite solves the problem jashkenas is talking about, which is that JavaScript automatically calls certain properties of your object behind the scenes in many situations, so you aren't completely free to use any key you want. You might be able to use a no-proto object like this as the internal datastore for a map, but by itself an object with arbitrarily assigned keys would cause a lot of problems unless you were very careful with it.