unset.js
490 Bytes
define(['./has'], function (has) {
/**
* Unset object property.
*/
function unset(obj, prop){
if (has(obj, prop)) {
var parts = prop.split('.'),
last = parts.pop();
while (prop = parts.shift()) {
obj = obj[prop];
}
return (delete obj[last]);
} else {
// if property doesn't exist treat as deleted
return true;
}
}
return unset;
});