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

Arguments casting to array. #311

Closed
EvanCarroll opened this issue Apr 14, 2015 · 4 comments
Closed

Arguments casting to array. #311

EvanCarroll opened this issue Apr 14, 2015 · 4 comments

Comments

@EvanCarroll
Copy link

The current advice,

To convert an array-like object to an array, use Array#slice.

function trigger() {
  var args = Array.prototype.slice.call(arguments);
  ...
}

Actually breaks v8's compiling optimizer, just fyi. Any function you do that to can not be optimized. See the bluebird docs for more info.

Also, see my question on StackOverflow.

@goatslacker
Copy link
Collaborator

In this particular case we're favoring readability > performance.

Directly assigning to an Array with a fixed length (like it mentions in the bluebird docs for "Workaround") is way faster anyway but that doesn't mean we should always favor that pattern.

@EvanCarroll
Copy link
Author

Well, just so long as you're comfortable totally forgoing javascript optimizations everywhere that pattern is used. Afaik, no browser can or will ever optimize if you leak arguments. For this reason, I find this to be bad advice. You're taking a shortcoming of the language (the arguments object), and advocating exactly the reason why arguments is a shortcoming.

It's not just the act of the copying to an array either. It's the entire containing function. The whole thing is marked un-optimizable.

@goatslacker
Copy link
Collaborator

Thankfully we've got rest in es6 so we don't have to ever use arguments :)

@ljharb
Copy link
Collaborator

ljharb commented Dec 23, 2015

Since now we should be using the rest operator, I'm going to close this.

@ljharb ljharb closed this as completed Dec 23, 2015
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

3 participants