Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
setPath
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Dec 22, 2011
1 parent cd09532 commit 1e94edd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions objects.js
Expand Up @@ -234,4 +234,15 @@ var has = exports.has = function (obj, match) {
//if match is a function, apply it to the corrisponding obj[key] //if match is a function, apply it to the corrisponding obj[key]
} }
return true return true
}

var setPath = exports.setPath = function (object, path, value) {

for (var i in path) {
var key = path[i]
if(object[key] == null) object[key] = (
i + 1 == path.length ? value : {}
)
object = object[key]
}
} }

0 comments on commit 1e94edd

Please sign in to comment.