Suppose I have a function that modifies an object's method:
var obj = { // some code addBefore : function(method,func){ //some code this.before[method].push(func); this[method] = function(){ this.before[method].forEach(function(key){key();}); this.old[method].call(this); } } And then you need to cut a piece of code from the modified method. Original:
function method(x){ var result = x*25; return result; } Due to the fact that I "modify" the function artificially, I need a function that transforms this method into the form:
function method(x){ this.before[method].forEach(function(key){key();}); var result = x*25; return result; } And not in the form:
this[method] = function(){ this.before[method].forEach(function(key){key();}); this.old[method].call(this); } those. Just need a function that takes as input a different function (f) and a string, deletes / replaces / adds a string in the function and returns a new function (f1).