Home > Web Front-end > JS Tutorial > JavaScript function parameter restrictions description_javascript skills

JavaScript function parameter restrictions description_javascript skills

WBOY
Release: 2016-05-16 18:15:59
Original
1179 people have browsed it
Test results:

There are 65535 under safari. That is ushort to store (2 bytes 16 1). More are ignored.

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. Don’t worry about it. After all, we know the bottleneck is at 65535.

Based on the above foundation. You can consider using [].push.apply(a,b) instead of a=a.concat(b) when connecting arrays;
We just need to note that for safari, the length of b cannot exceed 65535.
The problem with
concat is that the new array generated traverses the two arrays a and b, and then puts the elements of a and b in sequence.

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 ancient browsers such as ie6 chrome2 safari 3 firefox 2 are completely victorious in push. Even if some browsers are removed //a = [1,2 ,3]; Comment part. The efficiency is actually better than concat. Such as chrome7 dev and safari 5.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template