diff --git a/CHANGELOG b/CHANGELOG index 43db9e1..00ed9d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/base.js b/src/base.js index 143aa4c..c89aa55 100644 --- a/src/base.js +++ b/src/base.js @@ -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(); diff --git a/test/unit/base.html b/test/unit/base.html index fb0b210..97fe526 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -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(',') };