Hapi: request.query.hasOwnProperty causes "hasOwnProperty is not a function" error

Created on 4 Aug 2016  Â·  4Comments  Â·  Source: hapijs/hapi

I'm having a new issue with node v6.3.1 and hapi v14.1.0.

A handler function with request.query.hasOwnProperty('whatever') will result in a "request.query.hasOwnProperty is not a function" error.

Changing to Object.prototype.hasOwnProperty.call(request.query, 'whatever') works.

typeof request is 'object', so I'm not sure why this method is missing or why calling it from Object works.

non issue

Most helpful comment

This is expected. https://github.com/nodejs/node/pull/6289 modified the query object returned by the querystring module such that it uses a null prototype, and therefore does not inherit the base properties and methods of ordinary Object instances. This was done intentionally to address some bugs that are detailed in the PR. Your workaround is the proper alternative.

All 4 comments

This is expected. https://github.com/nodejs/node/pull/6289 modified the query object returned by the querystring module such that it uses a null prototype, and therefore does not inherit the base properties and methods of ordinary Object instances. This was done intentionally to address some bugs that are detailed in the PR. Your workaround is the proper alternative.

Thanks @jasnell. Closing issue.

Could a change to the querystring type file help with this? TypeScript should definitely be throwing an error

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arb picture arb  Â·  4Comments

AdriVanHoudt picture AdriVanHoudt  Â·  5Comments

jeffbski picture jeffbski  Â·  5Comments

hbinduni picture hbinduni  Â·  5Comments

kevinsimper picture kevinsimper  Â·  4Comments