Skip to content

Commit

Permalink
Look for properties down in the prototype chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
fauria committed Mar 5, 2015
1 parent a45c4a7 commit c4658c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DotObject.prototype.pick = function(path, obj, remove) {
if (path.indexOf(this.seperator) !== -1) {
keys = path.split(this.seperator);
for (i = 0; i < keys.length; i++) {
if (obj && obj.hasOwnProperty(keys[i])) {
if (obj && typeof obj === 'object' && keys[i] in obj) {
if (i === (keys.length - 1)) {
if (remove) {
val = obj[keys[i]];
Expand Down
19 changes: 19 additions & 0 deletions test/pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ describe('DJ value picker:', function() {

});

it('Should check down the object\'s prototype chain', function() {

var dj = new DJ();

var obj = {
'some': {
'other': 'value'
}
};

var objIns = Object.create(obj);

objIns.should.have.property('some');

var val = dj.pick('some.other', objIns);
val.should.be.an.Object;

});

});

0 comments on commit c4658c3

Please sign in to comment.