Spaces:
Paused
Paused
File size: 553 Bytes
9ada4bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/**
* Returns the source object of the given property on the target object
* (the target itself, any parent in its prototype, or null).
*/
export function findPropertySource(
target: object,
propertyName: string | symbol
): object | null {
if (!(propertyName in target)) {
return null
}
const hasProperty = Object.prototype.hasOwnProperty.call(target, propertyName)
if (hasProperty) {
return target
}
const prototype = Reflect.getPrototypeOf(target)
return prototype ? findPropertySource(prototype, propertyName) : null
}
|