Repository: sindresorhus/dot-prop (js)

Issue:
get() method's switch to object.prototype.propertyIsEnumerable broke my code
<!-- Issuehunt Badges -->

[<img alt="Issuehunt badges" src="https://issuehunt.io/r/sindresorhus/dot-prop/issues/46/badge.svg" />](https://issuehunt.io/r/sindresorhus/dot-prop/issues/46)

<!-- /Issuehunt Badges -->

This change was made in July 2016:

    use `object.prototype.propertyIsEnumerable instead of `Object.getOwnPropertyDescriptor`

Unfortunately, this change broke my code. Specifically, I was using it like this in the [Express](http://expressjs.com/) framework:

    dot = require( "dot-prop" );
    req.app.locals.foo = 1;
    console.log( "foo = " + dot.get( req, "app.locals.foo" ) );

where the `req` object is defined [here](http://expressjs.com/en/4x/api.html#req).

Before this change, `foo = 1` was logged.
After this change, `foo = undefined` was logged.

The problem appears to be that `req.app` isn't an enumerable property because it is an **inherited** property.

So, here's my question: why are we discriminating against inherited properties inside the `get()` method? That doesn't seem right to me.
<!-- Issuehunt content -->



> There is a $40.00 open bounty on this issue. Add more on [Issuehunt](https://issuehunt.io/r/sindresorhus/dot-prop/issues/46).
> - Checkout the [Issuehunt explorer](https://issuehunt.io/r/sindresorhus/dot-prop/) to discover more funded issues.
> - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on Issuehunt to raise funds.


<!-- /Issuehunt content-->

Pull request description:
Allow getting non-enumerable properties
Changes the way to check property for enumerability, fixes #46 

Patch:
diff --git a/index.js b/index.js
index a90f599..74a7a61 100644
--- a/index.js
+++ b/index.js
@@ -43,10 +43,6 @@ module.exports = {
 		}
 
 		for (let i = 0; i < pathArray.length; i++) {
-			if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) {
-				return value;
-			}
-
 			object = object[pathArray[i]];
 
 			if (object === undefined || object === null) {


Test patch:
diff --git a/test.js b/test.js
index a33361f..d9731b7 100644
--- a/test.js
+++ b/test.js
@@ -30,8 +30,8 @@ test('get', t => {
 		value: 'bar',
 		enumerable: false
 	});
-	t.is(dotProp.get(fixture2, 'foo'), undefined);
-	t.is(dotProp.get({}, 'hasOwnProperty'), undefined);
+	t.is(dotProp.get(fixture2, 'foo'), 'bar');
+	t.is(dotProp.get({}, 'hasOwnProperty'), Object.prototype.hasOwnProperty);
 
 	function fn() {}
 	fn.foo = {bar: 1};
@@ -50,6 +50,11 @@ test('get', t => {
 	t.false(dotProp.get('foo', 'foo.bar', false));
 	t.false(dotProp.get([], 'foo.bar', false));
 	t.false(dotProp.get(undefined, 'foo.bar', false));
+
+	class F4Class {}
+	F4Class.prototype.foo = 1;
+	const f4 = new F4Class();
+	t.is(dotProp.get(f4, 'foo'), 1); // #46
 });
 
 test('set', t => {