Do not access Object.prototype method 'hasOwnProperty' from target object.
225 if (!serviceOptionData) return <Skeleton height={48} width='100%' radius='xs' />
226
227 const hasAll = (categoryId: string) => {
228 if (!form.values.hasOwnProperty(categoryId)) return false229 return form.values[categoryId]?.every((item) => item.categoryId === categoryId && item.checked)
230 }
231 const hasSome = (categoryId: string) => {
Do not access Object.prototype method 'hasOwnProperty' from target object.
229 return form.values[categoryId]?.every((item) => item.categoryId === categoryId && item.checked)
230 }
231 const hasSome = (categoryId: string) => {
232 if (!form.values.hasOwnProperty(categoryId)) return false233 return (
234 !hasAll(categoryId) &&
235 form.values[categoryId]?.some((item) => item.categoryId === categoryId && item.checked)
Do not access Object.prototype method 'hasOwnProperty' from target object.
237 }
238
239 const toggleCategory = (categoryId: string) => {
240 if (!form.values.hasOwnProperty(categoryId)) return241 form.setValues({
242 [categoryId]: form.values[categoryId]?.map((value) => ({ ...value, checked: !hasAll(categoryId) })),
243 })
Description
It is preferable to call certain Object.prototype
methods through Object
on object instances instead of using the builtins directly.
Objects can have properties that shadow the builtins on Object.prototype
, potentially causing unintended behavior or denial-of-service security vulnerabilities.
For example, it would be unsafe for a webserver to parse JSON input from a client and call hasOwnProperty
directly on the resulting object, because a malicious client could send a JSON value like {"hasOwnProperty": 1}
and cause the server to crash.
It's better to always call these methods from Object.prototype
. For example, obj.hasOwnProperty("bar")
should be replaced with Object.prototype.hasOwnProperty.call(obj, "bar")
.
Bad Practice
let hasBarProperty = obj.hasOwnProperty("property");
let isPrototypeOfBar = obj.isPrototypeOf(property);
let barIsEnumerable = obj.propertyIsEnumerable("property");
Recommended
let hasBarProperty = Object.prototype.hasOwnProperty.call(obj, "property");
let isPrototypeOfBar = Object.prototype.isPrototypeOf.call(obj, property);
let barIsEnumerable = {}.propertyIsEnumerable.call(obj, "property");