Background: The query-string module , for example, is able to parse key=value&hello=universeon an object {key: 'value', hello: 'universe'}. However, the author of the module decided that the returned object does not have a prototype. In other words, this bastard object is created Object.create(null).
Problem: It would be convenient to use parsed.hasOwnProperty('hello'), but this is not possible without a prototype of the default object. Of course, it would be possible Object.prototype.hasOwnProperty.call(parsed, 'hello'), but I think we can all agree that such an expression kills-right after birth is ugly.
Question: How to convert a prototype object well in order to have a default prototype object and methods like hasOwnProperty? Also, can this be done without the use of a feared __proto__ or setPrototypeOf?
source
share