Test for Safari 6 bug
The code does not work in recent (Safari 6.0) versions of Safari on mobile iOS devices like iPad 2.
It seems the JIT has a bug when optimizing post-increment operations in tight loops.
Pressing click me multiple times in mobile Safari 6 yields different results after a while.
HTML
<button onclick="utility.testAndOutput()">Click Me!</button>
<div id="log"></div>
JavaScript
// dummy utility "class"
utility = {};
utility.testAndOutput = function(){
document.getElementById("log").innerHTML += "from " + zf(123,3);
};
function zf(num,digs)
{
var out = "";
var n = Math.abs(num);
for (digs; digs>0||n>0; digs--)
{
out = n%10 + out;
n = Math.floor(n/10);
}
return num<0?"-"+out:out;
}