Skip to content

Instantly share code, notes, and snippets.

@benbenbenbenbenben
Last active September 10, 2017 19:16
Show Gist options
  • Save benbenbenbenbenben/977d84e7002c24816fc8b313f11e7820 to your computer and use it in GitHub Desktop.
Save benbenbenbenbenben/977d84e7002c24816fc8b313f11e7820 to your computer and use it in GitHub Desktop.
// get a function's parameters as [...string]
(function() {
if (Function.prototype.parameters)
return;
Object.defineProperty(Function.prototype, "parameters", { get: function() {
var pattern = /^(?:(?:(?:function\s+[\w_\$][\w\d_\$]*)|function\s*|[\w_\$][\w\d_\$]*)(?:\(|[\w_\$])|\(|)(\s*(([\w_\$][\w\d_\$]*)([,\s]*)?)*)/gim
var matches = pattern.exec(this.toString())
return matches[1].split(',').map(s => s.trim()).filter(s => s.length)
}})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment