UNPKG

1.18 kBJavaScriptView Raw
1'use strict';
2
3var isObject = require('./object'),
4 isString = require('./string'),
5 handleCurry = require('./utils/handleCurry');
6
7/**
8 * Checks whether an object has own property
9 *
10 * **Aliases** _hasOwn_
11 *
12 * @function hasOwnProperty
13 *
14 * @example
15 * var is = require('predicates');
16 *
17 * var isCustomized = is.hasOwnProperty('delay');
18 *
19 * var Timer = function() {};
20 * Timer.prototype.delay = 100;
21 *
22 * var timer1 = new Timer();
23 * var timer2 = new Timer();
24 * timer1.delay = 1000;
25 *
26 * isCustomized(timer1) // true
27 * // same as
28 * is.hasOwnProperty('delay', timer1); // true
29 *
30 * isCustomized(timer2); // false
31 *
32 * @param {String} property
33 * @param {Object} [object]
34 * @throws {TypeError} if property is not a string
35 * @returns {(Boolean|Predicate)} bool if at least two arguments provided, otherwise a predicate
36 */
37module.exports = function hasOwnProperty(property) {
38 if (!isString(property)) {
39 throw new TypeError('Property name must be a string');
40 }
41 return handleCurry.call(this, arguments, function hasOwnPropertyPredicate(object) {
42 return isObject(object) && Object.prototype.hasOwnProperty.call(object, property);
43 });
44};
\No newline at end of file