Skip to content

Instantly share code, notes, and snippets.

@friedemannsommer
Last active June 1, 2016 09:30
Show Gist options
  • Save friedemannsommer/1d0840b6670abe418ae2 to your computer and use it in GitHub Desktop.
Save friedemannsommer/1d0840b6670abe418ae2 to your computer and use it in GitHub Desktop.
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