projen
Version:
CDK for software projects
31 lines (18 loc) • 731 B
Markdown
> A safer `.hasOwnProperty()`
Shortcut for `Object.prototype.hasOwnProperty.call(object, property)`.
You shouldn't use `.hasOwnProperty()` as it won't exist on [objects created with `Object.create(null)`](https://stackoverflow.com/a/12017703/64949) or it can have been overridden.
```
$ npm install has-own-prop
```
```js
const hasOwnProp = require('has-own-prop');
const object = Object.create(null);
object.unicorn = true;
object.hasOwnProperty('unicorn');
//=> 'TypeError: undefined is not a function'
hasOwnProp(object, 'unicorn');
//=> true
```