Skip to content

Instantly share code, notes, and snippets.

@pianosnake
pianosnake / hasOwnProperties.js
Created June 24, 2016 15:37
Recursive implementation of JavaScript hasOwnProperty().
//example:
//var nestedObj = {planet: {earth: {'@continent': 'africa'}}};
//hasOwnProperties(nestedObj, 'planet.earth.@continent') //returns true
//hasOwnProperties(nestedObj, 'planet.earth.@continent', 'africa') //returns true
//hasOwnProperties(nestedObj, 'planet.earth.unicorns') //returns false
hasOwnProperties: function(target, path, value){
if (typeof target !== 'object' || target === null) { return false; }
var parts = path.split('.');