Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

has-own-prop

sindresorhus10.1mMIT3.1.0TypeScript support: included

A safer .hasOwnProperty()

object, has, own, property

readme

has-own-prop

A safer .hasOwnProperty()

Shortcut for Object.prototype.hasOwnProperty.call(object, property). Also comes with a type guard for TypeScript users.

You shouldn't use .hasOwnProperty() as it won't exist on objects created with Object.create(null) or it can have been overridden.

Install

npm install has-own-prop

Usage

import hasOwnProperty from 'has-own-prop';

const object = Object.create(null);
object.unicorn = true;

object.hasOwnProperty('unicorn');
//=> 'TypeError: undefined is not a function'

hasOwnProperty(object, 'unicorn');
//=> true