Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function.arguments #6

Open
ljharb opened this issue May 28, 2015 · 2 comments
Open

function.arguments #6

ljharb opened this issue May 28, 2015 · 2 comments

Comments

@ljharb
Copy link
Collaborator

ljharb commented May 28, 2015

Should it return a frozen array every time it's evaluated? Is there any use case for which mutability of this array would be desired?

@ExE-Boss
Copy link

Arguably, it should always return the same mutable array for the current environment to match how the arguments object is mutable.

@ExE-Boss
Copy link

ExE-Boss commented Sep 29, 2020

I also consider function.arguments to be equivalent to capturing all arguments using the ... rest operator, eg.:

const foo = (bar, baz = 123) => {
	return {
		bar,
		baz,
		arguments: function.arguments,
	};
};

Is equivalent to the following ES2015 transpiled code:

const foo = (..._functionArguments) => {
	var { 0: bar, 1: baz = 123 } = _functionArguments;
	return {
		bar,
		baz,
		arguments: _functionArguments;
	};
};
Object.defineProperty(foo, "length", { value: 1, configurable: true });

Or transpiled to ES5:

var foo = function (bar) {
	var _functionArguments = [];
	for (var i = 0, length = arguments.length; i < length; i++) {
		_functionArguments[i] = arguments[i];
	}

	var baz = _functionArguments[1];
	if (baz === undefined) {
		baz = 123;
	}

	return {
		bar,
		baz,
		arguments: _functionArguments;
	};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants