Skip to content

Instantly share code, notes, and snippets.

@fitzgen
Created September 21, 2009 23:18
Show Gist options
  • Save fitzgen/190627 to your computer and use it in GitHub Desktop.
Save fitzgen/190627 to your computer and use it in GitHub Desktop.
function quote(fn) {
return typeof(fn.name) === "string" ?
fn.name :
fn.toString()
.replace("function ", "")
.replace(/\([\s\S]*/, "");
}
function funCall(fn) {
var args = Array.prototype.slice.call(arguments, 1),
mac = fn + "(",
arg, i;
for (i = 0; i < args.length; i++) {
arg = typeof(args[i]) === "string" ?
"'" + args[i] + "'" :
args[i];
mac = mac + arg;
if (i !== args.length - 1) {
mac = mac + ", ";
} else {
mac = mac + ");";
}
}
return mac;
}
eval(funCall(quote(alert), "hello"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment