JSFiddle - React, Tailwind, and code Playground

by ronilan

HTML

// rewrite function

JavaScript

function myRewrite(body){
	return body.replace('a', 'z');
}

function removeOuter(funcString){
	return funcString.substring(funcString.indexOf('{') + 1,funcString.lastIndexOf('}'));
}

function rewrite(func){
	let f = removeOuter(func.toString());
  f = myRewrite(f);
  AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
  f = new AsyncFunction(f);
  return f;
}


const func = function() {
	//
	console.log('the answer to everything is 42');
}

rewrite(func)()