I encountered this JS exception at work. Why is the browser always crashing?
In the beginning, I can only think of an endless loop. Maybe it is a condition for judging which is wrong, but it is not. After Google, I found an articleArticleFor details, see:
========================================================== ======================================
Article address:Http://www.zizhujy.com/blog/post/2012/03/18/Uncaught-RangeError-Maximum-call-stack-size-exceeded.aspx
I would like to thank the author for sharing this article. This article is completely reproduced from the above link, which is used as a backup.
I. Problems:
Today, when I made a webpage, I suddenly encountered such a javascript error:
Uncaught rangeerror: Maximum call stack size exceeded
I cannot explain it. The reason cannot be found for thousands of debugging.
On the surface, the memory is consumed too much because of too many recursion times, but myProgramNone of them use recursionAlgorithmAh.
Ii. Reasons:
After a long time, I finally found that the root cause of the problem was that two different JavaScript libraries were referenced in the webpage, and both libraries modified some methods of the original JavaScript Object, as a result, a circular reference occurs. Specifically, this is the case:
The webpage H references JS libraries A and B, and the math. Pow method is modified in A and B, as shown in:
If you modify the math. Pow () method only once, there will be no problem: first use math. Power to store the original math. Pow version, and then use the newCodeReplace math. Pow.
However, when math. Power = math. Pow is executed in the second database, math. Power is no longer the original version of math. Pow,
Because math. Pow has been changed to new code by the first database, the original version is called when math. Power () is called in the new math. Pow code,
But it calls itself. This leads to a loop!
Iii. solution:
Add a line of judgment code before replacement to avoid repeated use of the same method name.
Iv. Remarks:
Some may wonder why we should replace the original math. Pow () method? The replacement code here seems to not only reduce its efficiency,
Nothing. In fact, this is just an example of the cause of the problem, so it uses stupid code, but it is simple. Why should we replace math. Pow,
Because the original math. Pow () has a bug, that is, to calculate a negative number, for example, to the power of 1/3, an incorrect result Nan is returned.
I encountered this JS exception at work. Why is the browser always crashing?
In the beginning, I can only think of an endless loop. Maybe it is a condition for judging which is wrong, but it is not. After Google, I found an article. For details, refer:
========================================================== ======================================
Article address:Http://www.zizhujy.com/blog/post/2012/03/18/Uncaught-RangeError-Maximum-call-stack-size-exceeded.aspx
I would like to thank the author for sharing this article. This article is completely reproduced from the above link, which is used as a backup.
I. Problems:
Today, when I made a webpage, I suddenly encountered such a javascript error:
Uncaught rangeerror: Maximum call stack size exceeded
I cannot explain it. The reason cannot be found for thousands of debugging.
On the surface, memory is too much consumed because of too many recursion times, but none of my programs use recursive algorithms.
Ii. Reasons:
After a long time, I finally found that the root cause of the problem was that two different JavaScript libraries were referenced in the webpage, and both libraries modified some methods of the original JavaScript Object, as a result, a circular reference occurs. Specifically, this is the case:
The webpage H references JS libraries A and B, and the math. Pow method is modified in A and B, as shown in:
For math. pow () method is modified only once, so there is no problem: use math first. power stores math. the original version of pow, and then replace math with the new code. pow.
However, when math. Power = math. Pow is executed in the second database, math. Power is no longer the original version of math. Pow,
Because math. Pow has been changed to new code by the first database, the original version is called when math. Power () is called in the new math. Pow code,
But it calls itself. This leads to a loop!
Iii. solution:
Add a line of judgment code before replacement to avoid repeated use of the same method name.
Iv. Remarks:
Some may wonder why we should replace the original math. Pow () method? The replacement code here seems to not only reduce its efficiency,
Nothing. In fact, this is just an example of the cause of the problem, so it uses stupid code, but it is simple. Why should we replace math. Pow,
Because the original math. Pow () has a bug, that is, to calculate a negative number, for example, to the power of 1/3, an incorrect result Nan is returned.