77 * MIT Licensed
88 */
99
10- var type = require ( 'type-detect' ) ;
11-
1210/**
1311 * ### .hasProperty(object, name)
1412 *
15- * This allows checking whether an object has
16- * named property or numeric array index .
13+ * This allows checking whether an object has own
14+ * or inherited from prototype chain named property .
1715 *
1816 * Basically does the same thing as the `in`
19- * operator but works properly with natives
20- * and null/undefined values .
17+ * operator but works properly with null/undefined values
18+ * and other primitives .
2119 *
2220 * var obj = {
2321 * arr: ['a', 'b', 'c']
@@ -39,31 +37,20 @@ var type = require('type-detect');
3937 * hasProperty(obj.arr, 3); // false
4038 *
4139 * @param {Object } object
42- * @param {String|Number } name
40+ * @param {String|Symbol } name
4341 * @returns {Boolean } whether it exists
4442 * @namespace Utils
4543 * @name hasProperty
4644 * @api public
4745 */
4846
49- var literals = {
50- 'number' : Number ,
51- 'string' : String ,
52- } ;
5347function hasProperty ( obj , name ) {
54- var objType = type ( obj ) ;
55- // Bad Object, obviously no props at all
56- if ( objType === 'null' || objType === 'undefined' ) {
48+ if ( typeof obj === 'undefined' || obj === null ) {
5749 return false ;
5850 }
5951
60- // The `in` operator does not work with certain literals
61- // box these before the check
62- if ( literals [ objType ] && typeof obj !== 'object' ) {
63- obj = new literals [ objType ] ( obj ) ;
64- }
65-
66- return name in obj ;
52+ // The `in` operator does not work with primitives.
53+ return name in Object ( obj ) ;
6754}
6855
6956/* !
0 commit comments