-
-
Notifications
You must be signed in to change notification settings - Fork 96
hasOwnProperty is not a function #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @lucianobosco due to a potential vulnerability with unsafely setting the diffed properties on the returned diff object, the diffed object is now created using In your case you could spread the diff object into another object with the default prototype functions available. const diffs = diff(originalResource.value, resource.value)
const d = { ...diffs }
const payload = {
...(d.hasOwnProperty('name') && { name: resource.value.name }),
...(d.hasOwnProperty('slug') && { slug: resource.value.slug }),
...(d.hasOwnProperty('visible') && { visible: resource.value.visible }),
...(d.hasOwnProperty('postCategory') && { post_category_id: resource.value.postCategory?.id || null }),
...(d.hasOwnProperty('parent') && { parent_id: resource.value.parent?.id || null })
} |
Thanks a lot! That works |
Note that inner objects doesn't have prototype too, so even if you spread the object you might face the same const diffs = diff(originalResource.value, resource.value)
const d = { ...diffs }
d.innerObj.hasOwnProperty('myProp') // will throw hasOwnProperty is not a function A different solution than spreading the diff object could be to use Object.hasOwnProperty.call(diffs, prop) |
Since last update I'm getting
hasOwnProperty is not a function
I used to create a payload with differences to be sent to my API through axios:
Did anything change in regards to returned response from method
diff()
. In that case, how can I getdiff()
properties changed in order to create a new payload object?The text was updated successfully, but these errors were encountered: