// I am trying to make a clone of String's replace function
// and then re-define the replace function (with a mind to
// call the original from the new one with some mods)
String.prototype.replaceOriginal = String.prototype.replace
String.prototype.replace = {}
This next line is now broken – how do I fix?
"lorem ipsum".replaceOriginal(/(orem |um)/g,'')
The only possible issue is that your code is executed twice, which causes problems: The real original
.replacewill disappear.To avoid such problems, I strongly recommend to replace built-in methods using the following general method:
.apply(): Usually, thethisobject is vital for (prototype) methods.