archives

« Bugzilla Issues Index

#2339 — Function.getArgs


Hello.

ES6's rest and default parameter is perfect for arguments.
It seems that arguments is not necessary anymore.

However ES would not enforce arity because of traditional reasons.
and does not support function overloading.

'arguments' can solve this problem.
I think traditional vararg-style arguments is not too bad.

Thus I propose a tiny API, Function.getArgs(), which returns current function's arguments array instead of new syntax which can make ES more complex.

The following is an implementation and usage of Function.getArgs() by JavaScript. It should be implemented by native code.

Function.getArgs = Function.getArgs || function getArgs(){
if(typeof getArgs.caller != "function") throw new Error();
return Array.prototype.slice.call(getArgs.caller.arguments, 0);
};

function foo(){
var args = Function.getArgs();
console.log(args.toString());
}

foo(123,456);

Thanks.

(Sorry for bad English.)


see https://github.com/allenwb/ESideas/blob/master/ES7MetaProps.md


Proposals should use the proposal process documented here: https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md.