Skip to content

Instantly share code, notes, and snippets.

@sms-system
Last active March 16, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sms-system/fd33604fb5aee74fadddc085d12939f9 to your computer and use it in GitHub Desktop.
Save sms-system/fd33604fb5aee74fadddc085d12939f9 to your computer and use it in GitHub Desktop.
Get function argument names
Object.defineProperty(Function.prototype, 'args', {
get () {
return this
.toString()
.replace(/\/\/.*$/mg,'') // COMMENT
.replace(/\/\*.*?\*\//g, '') // COMMENT
.replace(/\/.*?(?<!\\)\//g, '') // REGEXP
.replace(/'.*?(?<!\\)'/g, '') //STRING
.replace(/\s+/g,'')
.split(')')[0]
.split('(')[1]
.split(',')
.filter(a => !a.startsWith('...') && a !== '')
.map(a => a.split('=')[0])
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment