-
Notifications
You must be signed in to change notification settings - Fork 29
Fix #89 Hooks cannot remove inherited properties #90
Fix #89 Hooks cannot remove inherited properties #90
Conversation
if (!obj || !obj.hasOwnProperty(args[i])) { | ||
return false; | ||
function findFieldOwner(obj, field) { | ||
const nestedFields = field.split('.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just a longer way of saying !obj || typeof obj[args[i]] === 'undefined'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using typeof obj[args[i]] === undefined
, we will not know whether the property is belong to the current obj
or ancestor prototype (direct owner). To delete that property, we need to delete it from the direct owner. So, we need to use hasOwnProperty
.
(About the const name nestedFields
, I just make it more explicit but I can just use args[i]
if you think it's more concise.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the code in my new commit to make it looks cleaner and more concise. Plz take a look. (I'll squash it later).
Are you sure that const o = { test: 'me' }
const oo = Object.create(o);
delete oo.test;
console.log(oo); And I am getting an empty object logged. |
It's the effect of prototype inheritance.
|
Done. Released in v1.5.6. Thank you for bearing with me 😄 |
Never mind @daffl. It took me several days before figuring it out too! |
Fix #89 issue