Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function functionArguments(fn) {
if (fn.length > 0) {
var fnString = Function.prototype.toString.call(fn);
var firstIndex = fnString.indexOf('(');
var lastIndex = fnString.indexOf(')');
if (firstIndex > -1 && lastIndex > firstIndex) {
firstIndex++;
return fnString.substr(firstIndex, lastIndex - firstIndex).replace(/\s+/g, '').split(',');
}
}
return [];
}
function functionArguments(fn:Function):Array<string> {
if (fn.length > 0) {
let fnString = Function.prototype.toString.call(fn);
let firstIndex = fnString.indexOf('(');
let lastIndex = fnString.indexOf(')');
if (firstIndex > -1 && lastIndex > firstIndex) {
firstIndex++;
return fnString.substr(firstIndex, lastIndex - firstIndex).replace(/\s+/g, '').split(',');
}
}
return [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment