JavaScript function parameter restrictions.

Source: Internet
Author: User
Real parameter restrictions of JavaScript Functions.
I vaguely remember what I have mentioned in this book that the actual parameter limit is 32? Now I guess it's wrong. He might be talking about 32-bit. Test results:

Safari contains 65535. That is, ushort is used for storage (2 bytes, 16 bytes, and 1). For more information, ignore.

Other browsers are at least Int. maxvalue. It is said that Firefox or even long is used to maintain real parameters. Other browsers may be Int or uint. This doesn't matter. After all, we know that the bottleneck is 65535.


Based on the above basics, you can use []. Push. Apply (A, B) to replace a = A. Concat (B ); We only need to note that for Safari, the length of B cannot exceed 65535. The problem with Concat is that the new array is generated, the arrays A and B are traversed, and the elements A and B are placed in order.
TestCode: var COUNT = 100000, A = [1, 2, 3], B = [4, 5, 6], r = [], I, D;

d = new date;
for (I = count; I --;) {
. concat (B);
}< span>
r [0] = new date-D;

d = new date;
for (I = count; I --;) {
r. push. apply (a, B);
// A = [1, 2, 3];
}< span>
r [1] = new date-D;

alert (r);

it can be concluded that even the push of an old browser like IE6 chrome2 Safari 3 Firefox 2 is perfect, even if some browsers are removed // A = [1, 2, 3]; comments section. the efficiency is better than Concat. such as chrome7 Dev and Safari 5.

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.