Copy codeThe Code is as follows:
A = new Array ();
B = new Array (125624 );
A. push. apply (a, B );
The above code throws the following exception in chrome of mac:
Copy codeThe Code is as follows:
Uncaught RangeError: Maximum call stack size exceeded
If you change the Array to B = new Array (125623), the problem is that a small element is enough. After testing, other browsers also have a large Array, but the critical values of different browsers vary.
Search for the http://stackoverflow.com/questions/1374126/how-to-append-an-array-to-an-existing-javascript-array/17368101#17368101 found that someone encountered such a pitfall:
Copy codeThe Code is as follows:
Array. prototype. extend = function (other_array ){
/* You shoshould include a test to check whether other_array really is an array */
Other_array.forEach (function (v) {this. push (v)}, this );
}
The advice is to be honest and practical, not only to avoid exceptions of large arrays, but also to consider forEach from the performance perspective is the fastest
This trap gives me two points of thinking:
1. Some fancy usage such as. push. apply (a, B); or apply it to interview questions. In practice, we should take more honest steps to avoid exceptions and performance pitfalls, for example, there are a small number of 3D network topology spring la s for dozens of nodes, A real big data volume, such as the HT for Web 3D Big Data performance example in this article, can be used to test the problem.
2, http://stackoverflow.com/questions/1374126 from stackoverflow to find the answer should not just stare at the most votes, the truth is often in the hands of a few people, 259 votes of the answer is a pitfall, 34 votes is the most perfect analysis: