41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
/**
|
|
* @file Used to determine whether an object has an own property with the specified property key.
|
|
* @see {@link http://www.ecma-international.org/ecma-262/6.0/#sec-hasownproperty|7.3.11 HasOwnProperty (O, P)}
|
|
* @version 3.2.0
|
|
* @author Xotic750 <Xotic750@gmail.com>
|
|
* @copyright Xotic750
|
|
* @license {@link <https://opensource.org/licenses/MIT> MIT}
|
|
* @module has-own-property-x
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var toObject = require('to-object-x');
|
|
var toPropertyKey = require('to-property-key-x');
|
|
var hop = require('cached-constructors-x').Object.prototype.hasOwnProperty;
|
|
|
|
/**
|
|
* The `hasOwnProperty` method returns a boolean indicating whether
|
|
* the `object` has the specified `property`. Does not attempt to fix known
|
|
* issues in older browsers, but does ES6ify the method.
|
|
*
|
|
* @param {!Object} object - The object to test.
|
|
* @throws {TypeError} If object is null or undefined.
|
|
* @param {string|Symbol} property - The name or Symbol of the property to test.
|
|
* @returns {boolean} `true` if the property is set on `object`, else `false`.
|
|
* @example
|
|
* var hasOwnProperty = require('has-own-property-x');
|
|
* var o = {
|
|
* foo: 'bar'
|
|
* };
|
|
*
|
|
*
|
|
* hasOwnProperty(o, 'bar'); // false
|
|
* hasOwnProperty(o, 'foo'); // true
|
|
* hasOwnProperty(undefined, 'foo');
|
|
* // TypeError: Cannot convert undefined or null to object
|
|
*/
|
|
module.exports = function hasOwnProperty(object, property) {
|
|
return hop.call(toObject(object), toPropertyKey(property));
|
|
};
|