How inherited properties are handled
masterBy default, object-path only accesses an object's own properties. If you attempt to get an inherited property, it will return undefined (or your specified default).
To include inherited properties, you have two options:
- Create a new instance using
create({ includeInheritedProps: true }). - Use the pre-configured
withInheritedPropsinstance.
Security Warning: When using inherited properties mode, object-path will throw an exception if you attempt to access magic properties like __proto__ or constructor to prevent prototype pollution.
var objectPath = require("object-path");
// Option 1: Create custom instance
var objectPathWithInheritedProps = objectPath.create({includeInheritedProps: true});
// Option 2: Use built-in instance
var objectPathWithInheritedProps = objectPath.withInheritedProps;
// Usage with inherited props
var proto = { notOwn: { prop: 'a' } };
var obj = Object.create(proto);
objectPath.withInheritedProps.get(obj, 'notOwn.prop'); // returns 'a'