Closed daffl closed 3 years ago
Curious, first time seeing:
Object.getOwnPropertyDescriptor(context, 'result') === undefined
Used instead of classic:
Object.prototype.hasOwnProperty.call(context, 'result')
Is there any difference?
I believe it ends up being the same thing but Object.getOwnPropertyDescriptor
is a more "recent" (ES5) spec and only applies to the actual object (instead the entire prototype chain) which I think is the right approach here since you can only set context.result
on the actual object.
instead the entire prototype chain
Object.prototype.hasOwnProperty
does the same, since otherwise it is not Own
.
Just wanted to check, maybe there were some specific use case for which getOwnPropertyDescriptor
were used here.
Just tested with hasOwnProperty
and it also works fine. Updated the PR to use that since it's probably faster than getting the descriptor object.
If there are no objections, I can roll it out in a new release.
No real objections from me.
Only small note - people do call Object.prototype.hasOwnProperty
, not Object.hasOwnProperty
. (But since it resolves to the same thing in the end - because Object
is an object instance too after all - it does not matter much.)
:shipit:
This pull request allows to set
context.result
toundefined
in a before hook as suggested by @vonagam. It should be fully backwards compatible.Closes https://github.com/feathersjs/hooks/issues/69