When you are building your web based calculator using jQuery Calx, it is a bit hard to track which cell refer to which cell, and sometimes circular reference occurred where some cell refer to itself, causing infinite loop of calculation operation and exceed the maximum call stack that can be handled by the javascript engine.

For example:

  • A1 is a cell with some value
  • B1 is a cell with formula = A1+D1
  • C1 is a cell with formula = B1+10
  • D1 is a cell with formula = C1*3

In this case, when B1 is calculated, it will calculate it’s dependencies first, which is A1 and D1, then D1 will trigger calculation on C1 and so on until it reach B1 again, and the process will never be finished. This is what we called as circular reference, causing a never ending process or an infinite loop, and usually trigger a javascript engine to shout at you : “Hey Bro! Maximum call stack size is exceeded, I can’t handle it for you any more!”

Fortunately, jQuery Calx comes with circular reference detector to help find circular reference in the calculator easily, but it is disabled by default, since it is quite slow operation and only useful in development mode. To enable this feature, you can tell jQuery Calx to enable it when initializing, and Calx will warn you if there is circular reference detected :

And now you will never scratch your head to find out why jQuery Calx tell the the javascript engine to shout at you.