You are currently browsing the archives for the reflection tag.

Arguments’ names in JavaScript

This is more of a reminder to myself, but it can be useful to anyone wishing to add a little more reflection to JS :

Function.prototype.args = function () {
  return this.toString()
    .match(/\(([^)]*)\)/)[1]
    .replace(/\s*/g, ").split(',');
}
function foo (bar, baz, quux) {
  return 42;
}
foo.args();
// = [bar, baz, quux]