Skip to content

Instantly share code, notes, and snippets.

@hkan
Created June 13, 2014 11:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hkan/555d79173c4ecf18e31b to your computer and use it in GitHub Desktop.
Object Prototype
Object.defineProperty(Object.prototype, "setDotNotated", {
value: function (dotNotation, value) {
var arrayOfNames = dotNotation.split('.');
var last = arrayOfNames.pop();
var tmp = this;
for (var i in arrayOfNames) {
if (!arrayOfNames.hasOwnProperty(i))
continue;
if (!tmp[arrayOfNames[i]])
tmp[arrayOfNames[i]] = {};
tmp = tmp[arrayOfNames[i]];
}
tmp[last] = value;
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment