node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »

has-own-prop

has-own-prop Build Status

A safer .hasOwnProperty()

Shortcut for Object.prototype.hasOwnProperty.call(obj, prop).

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 --save has-own-prop

Usage

var hasOwnProp = require('has-own-prop');
 
var obj = Object.create(null);
obj.unicorn = true;
 
obj.hasOwnProperty('unicorn');
//=> TypeError: undefined is not a function 
 
hasOwnProp(obj, 'unicorn');
//=> true 

License

MIT © Sindre Sorhus