Last active
March 29, 2016 15:34
-
-
Save co3moz/b6bc4bbfa825b60c3812 to your computer and use it in GitHub Desktop.
Get function parameter names in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.getParameters = function () { | |
return this._parameters || (this._parameters = /function *(?:.*?)\((.*?)\)/.exec(this + "")[1].split(/,/g).map(Function.prototype.call, String.prototype.trim)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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