Make Function#argumentNames work with named functions. Closes #9826

This commit is contained in:
Tobie Langel 2007-10-14 10:54:06 +00:00
parent 96af1b7579
commit 7dda50a7c9
3 changed files with 10 additions and 1 deletions

View File

@ -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]

View File

@ -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;
},

View File

@ -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) {