/** Custom Supplant Method **/
String.prototype.customSupplant = function(obj) {
return this.replace (/{([^{}]*)}/g,
function (match, propPath) {
var props = propPath.split('.');
var result = obj;
for (var i = 0; i < props.length; i++) {
result = result[props[i]];
}
return typeof result === 'string' || typeof result === 'number' ? result : match;
}
);
};
Crockford may be considered a JavaScript Grand Wizard, however his prototype lacks support for replacing properties in multiple level objects.
I am seeking an enhanced version of the supplant function that can handle replacement of nested object properties like '{post.detailed}'. Can anyone assist with creating such a revised version?