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

Use Array.slice() method for slicing arguments inside Events.trigger() #1511

Closed
wants to merge 1 commit into from
Closed

Conversation

pankaj28843
Copy link

[].slice.call(arguments, 1) can be used for slicing an Array like object instead of a for loop. This question posted on Stackoverflow suggests that slice is faster than for loop.

@braddunbar
Copy link
Collaborator

Mornin @psjinx, thanks for your patch!

a.slice() is in fact faster than a loop when copying the entire array. However, we are leaving out the first element in this case, and a.slice(1) is much slower than using a loop. If you're interested in the details, #1284 includes a discussion and appropriate benchmarks.

@braddunbar braddunbar closed this Jul 27, 2012
@pankaj28843
Copy link
Author

@braddunbar thanks for quick reply!

I am new to backbone.js and was trying to learn internals by reading source code. I think reason for using for loop should be there (before for loop) in a comment as discussed in #1284

@braddunbar braddunbar reopened this Jul 27, 2012
@braddunbar
Copy link
Collaborator

Fantastic! That's the best way to learn it.

I've added a comment in #1512. Please let us know if you find any other confusing points or inconsistencies. :)

jashkenas added a commit that referenced this pull request Jul 27, 2012
Fix #1511 - Add a comment explaining performance concerns in `trigger`.
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

Successfully merging this pull request may close these issues.

2 participants