JavaScript function parameter restriction description _javascript tips

Source: Internet
Author: User
Test results:

Safari is 65,535. That is, the ushort to store (2 bytes 16 1). More is ignored.

The other browsers are at least Int. MaxValue. It is said that Firefox even uses long to maintain real parameters.
Other browsers may be int or maybe uint. This doesn't matter. After all we know the bottleneck in 65535.

Based on the above basis. You can consider using [].push.apply (a,b) instead of A=a.concat (b) when connecting arrays;
We just need to be aware that B's length cannot exceed 65535 for safari OK.
The problem with concat is to generate a new array and traverse A and B two arrays, and then put the elements a and b in turn.

Test code:
var count = 100000, a = [1,2,3], b = [4,5,6], r = [], I, D;

d = new Date;
for (i = count; i--;) {
A.concat (b);
}
R[0] = new date-d;  


d = new Date;
for (i = count; i--;) {
R.push.apply (A,B);
A = [1,2,3];
}
R[1] = new date-d;  

Alert (R);

It can be concluded that even the IE6 chrome2 Safari 3 Firefox 2, an old browser push, is also a triumph, with individual browsers removing //a = [1,2,3]; the annotation section. Efficiency is better than concat. Chrome7 Dev and Safari 5.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.