has-own-prop
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 3.1.0
    100
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 3.1.0
    100
  • 3.0.0
    64
  • 2.0.0
    2,240,512
  • 1.0.1
    829
  • 1.0.0
    25

Package Sidebar

Install

npm i has-own-prop

Weekly Downloads

2,241,530

Version

3.1.0

License

MIT

Unpacked Size

2.97 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus