-
Notifications
You must be signed in to change notification settings - Fork 10
Description
I'm on a roll with a paranoia series... Another interesting question that I don't have relevant experience to base a strong opinion on.
@ljharb asked an interesting question in #26:
I hope result.flags is a null object?
Short version: no, should we do that?
Long version
The current answer is no, initialised with
const result = {
flags: {},
values: {},
positionals: []
};
I like the purity of a null object, but it has a slightly alarming behaviour in logging for users unaware of the behaviour:
% node -e 'a=Object.create(null); a.foo="bar"; console.log(a)'
[Object: null prototype] { foo: 'bar' }
The documentation covers at some lengths the complications:
which can lead to some support questions:
- https://stackoverflow.com/questions/56298481/how-to-fix-object-null-prototype-title-product/56298574
I like the idea of using a null object in theory. With zero-config parsing in parseArg
there is arguably more reason to consider null prototype. However, I don't have any practical experience with working with null objects. I am interested in comments from people with experience, and of how new users cope.