Copy Code code as follows:
A = new Array ();
b = new Array (125624);
A.push.apply (A, b);
The above code throws the following exception under the Mac Chrome
Copy Code code as follows:
uncaught rangeerror:maximum Call stack size exceeded
If you change the array to B = new Array (125623), small one element is good, test the other browsers also have a large array of errors, but different browser thresholds vary.
Searched the http://stackoverflow.com/questions/1374126/how-to-append-an-array-to-an-existing-javascript-array/17368101# 17368101 found that someone had encountered such a pit:
Copy Code code as follows:
Array.prototype.extend = function (Other_array) {
/* You should include a test to check whether Other_array really are an array */
Other_array.foreach (function (v) {This.push (v)}, this);
}
The advice given is to be honest with foreach, not only to avoid the exception of large arrays, but also to consider foreach as the fastest in terms of performance
This little pit gave me two points to think about:
1. Some fancy usages such as a.push.apply (A, b) or for the face of the test to install force on the line, or more to take the honest route to avoid encountering anomalies and performance of the pits, such as the small number of such as this dozens of nodes of the 3D network topology Spring layout example to play is not a problem, This 3D large data performance example of a really large amount of data, such as the HT for Web in this article, can test the problem.
2, http://stackoverflow.com/questions/1374126 from StackOverflow to find answers when not only stare at the most votes, the truth is often in the hands of a few people, the following figure 259 votes answer is a pit, 34 votes is the most perfect analysis: