StrMap backing object inherits from Object.prototype and lookup uses in
Closed this issue · 6 comments
I imagine lookup will think that keys like "toString" and "hasOwnProperty" exist in the object, even though the functions that rely on Object.keys or iteration through for-in won't see these properties because they're non-enumerable. I haven't tested this, but I'm pretty sure I'm right just by looking at the implementation.
Yeah, I'm pretty sure you're right too.
There's two possible solutions:
- use a
hasOwnPropertytest instead ofin - use
Object.create(null)as the backing object
I'd probably decide which to do based on performance. I'm going to guess the first option is better optimised in most implementations right now, but tests should be done to confirm.
Interesting, I wasn't aware of option 2 - I just assumed we'd have to use hasOwnProperty. You get a truly empty prototype with Object.create(null) then?
Yep.
@garyb is this fixed now after cca72e0#diff-f398949aafcfd55358d80eec690ee116?