Skip to content

Instantly share code, notes, and snippets.

@co3moz
Last active March 29, 2016 15:34
Show Gist options
  • Save co3moz/b6bc4bbfa825b60c3812 to your computer and use it in GitHub Desktop.
Save co3moz/b6bc4bbfa825b60c3812 to your computer and use it in GitHub Desktop.
Get function parameter names in javascript
Function.prototype.getParameters = function () {
return this._parameters || (this._parameters = /function *(?:.*?)\((.*?)\)/.exec(this + "")[1].split(/,/g).map(Function.prototype.call, String.prototype.trim));
}
function Find(what, to) {
}
Find.getParameters(); // ["what", "to"]
var f = function (hello) {}
f.getParameters(); // ["hello"]
function are_(happy, you) {}
are_.name + are_.getParameters().reverse().join("_"); // "are_you_happy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment