getown
v1.0.0
Published
Lookup an object property only if it's its own property.
Downloads
1,391
Readme
getown
Lookup an object property only if it's its own property.
API
This module exports one function:
getown(obj, prop, fallback)
Returns obj[prop]
if obj
is truthy and has an own property prop
,
otherwise returns fallback
.
Usage
from test/usage.mjs:
import getown from 'getown';
const dict = { foo: 'bar' };
same(getown(dict, 'foo'), 'bar');
same(getown(dict, 'bar'), undefined);
same(getown(dict, 'bar', 321), 321);
same(typeof dict.toString, 'function');
same(getown(dict, 'toString'), undefined);
Known issues
- Needs more/better tests and docs.
License
ISC