Permalink
Browse files

setPath

  • Loading branch information...
1 parent cd09532 commit 1e94edda9c8deb99dbe80429ba91153f81994ef1 @dominictarr committed Dec 22, 2011
Showing with 11 additions and 0 deletions.
  1. +11 −0 objects.js
View
@@ -234,4 +234,15 @@ var has = exports.has = function (obj, match) {
//if match is a function, apply it to the corrisponding obj[key]
}
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.