prototype: Add Function#argumentNames, which returns an ordered array of the function's named arguments.
This commit is contained in:
parent
5645a0783f
commit
90c9c69ff0
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Add Function#argumentNames, which returns an ordered array of the function's named arguments. [sam]
|
||||
|
||||
* Add Prototype.Browser.MobileSafari which evaluates to true on the iPhone's browser. [sam]
|
||||
|
||||
* Optimize Selector#match and Element#match for simple selectors. Closes #9082. [Andrew Dupont]
|
||||
|
@ -79,6 +79,11 @@ Object.extend(Object, {
|
||||
});
|
||||
|
||||
Object.extend(Function.prototype, {
|
||||
argumentNames: function() {
|
||||
var names = this.toString().match(/^function\s*\((.*?)\)/)[1].split(",").invoke("strip");
|
||||
return names.length == 1 && !names[0] ? [] : names;
|
||||
},
|
||||
|
||||
bind: function() {
|
||||
if (arguments.length < 2 && arguments[0] === undefined) return this;
|
||||
var __method = this, args = $A(arguments), object = args.shift();
|
||||
|
@ -56,6 +56,13 @@
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testFunctionArgumentNames: function() { with(this) {
|
||||
assertEnumEqual([], (function() {}).argumentNames());
|
||||
assertEnumEqual(["one"], (function(one) {}).argumentNames());
|
||||
assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
|
||||
assertEqual("$super", (function($super) {}).argumentNames().first());
|
||||
}},
|
||||
|
||||
testFunctionBind: function() { with(this) {
|
||||
function methodWithoutArguments() { return this.hi };
|
||||
function methodWithArguments() { return this.hi + ',' + $A(arguments).join(',') };
|
||||
|
Loading…
Reference in New Issue
Block a user