No tengo remota idea para que propósito puede servir, pero es de las funciones que un dia puede que se necesite más adelante y mejor tenerla guardada.
function getArgs(func) {
// First match everything inside the function argument parens.
var args = func.toString().match(/function\s.*?\(([^)]*)\)/)[1];
// Split the arguments string into an array comma delimited.
return args.split(",").map(function(arg) {
// Ensure no inline comments are parsed and trim the whitespace.
return arg.replace(/\/\*.*\*\//, "").trim();
}).filter(function(arg) {
// Ensure no undefineds are added.
return arg;
});
}
Su funcionamiento es el siguiente
function tuFuncion(arg1, arg2,arg3) {
}
console.log(getArgs(tuFuncion)); // ["arg1", "arg2", "arg3"]
Fuente: David Walsh - Detect Function Argument Names with Javascript

0 comentarios:
Publicar un comentario