has-own-prop
A safer `.hasOwnProperty()`
Last updated 3 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install has-own-prop 
SYNC missed versions from official npm registry.

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

Current Tags

  • 3.1.0                                ...           latest (3 years ago)

5 Versions

  • 3.1.0                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 5
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE