diff --git a/CHANGELOG b/CHANGELOG index 3318851..f7b8493 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make Function#argumentNames work with named functions. Closes #9826. [Samuel Lebeau] + * Add Object.isHash. [Tobie Langel] * Performance improvements to String#times. [Martin Ström] diff --git a/src/base.js b/src/base.js index 1ea0ba7..f73c9f9 100644 --- a/src/base.js +++ b/src/base.js @@ -154,7 +154,7 @@ Object.extend(Object, { Object.extend(Function.prototype, { argumentNames: function() { - var names = this.toString().match(/^[\s\(]*function\s*\((.*?)\)/)[1].split(",").invoke("strip"); + var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); return names.length == 1 && !names[0] ? [] : names; }, diff --git a/test/unit/base.html b/test/unit/base.html index 2941793..12a8d80 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -140,6 +140,13 @@ assertEnumEqual(["one"], (function(one) {}).argumentNames()); assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames()); assertEqual("$super", (function($super) {}).argumentNames().first()); + + function named1() {}; + assertEnumEqual([], named1.argumentNames()); + function named2(one) {}; + assertEnumEqual(["one"], named2.argumentNames()); + function named3(one, two, three) {}; + assertEnumEqual(["one", "two", "three"], named3.argumentNames()); }}, testFunctionBind: function() { with(this) {