Make Function#argumentNames work with named functions. Closes #9826
This commit is contained in:
parent
96af1b7579
commit
7dda50a7c9
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue