diff --git a/lib/getobject.js b/lib/getobject.js index e4006fe..881f695 100644 --- a/lib/getobject.js +++ b/lib/getobject.js @@ -23,6 +23,8 @@ function getParts(str) { getobject.get = function(obj, parts, create) { if (typeof parts === 'string') { parts = getParts(parts); + } else { + parts = parts.slice(0); } var part; @@ -40,7 +42,11 @@ getobject.get = function(obj, parts, create) { // Set a deeply-nested property in an object, creating intermediary objects // as we go. getobject.set = function(obj, parts, value) { - parts = getParts(parts); + if (typeof parts === 'string') { + parts = getParts(parts); + } else { + parts = parts.slice(0); + } var prop = parts.pop(); obj = getobject.get(obj, parts, true); @@ -51,7 +57,11 @@ getobject.set = function(obj, parts, value) { // Does a deeply-nested property exist in an object? getobject.exists = function(obj, parts) { - parts = getParts(parts); + if (typeof parts === 'string') { + parts = getParts(parts); + } else { + parts = parts.slice(0); + } var prop = parts.pop(); obj = getobject.get(obj, parts); diff --git a/package.json b/package.json index 364155f..58835c9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "getobject", "description": "get.and.set.deep.objects.easily = true", - "version": "0.1.0", + "version": "0.1.2", "homepage": "https://github.com/cowboy/node-getobject", "author": { "name": "\"Cowboy\" Ben Alman",