Skip to content

Instantly share code, notes, and snippets.

@hkan
Created Jun 13, 2014
Embed
What would you like to do?
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