Omirion Posted March 12, 2010 Share Posted March 12, 2010 function test(myTrig,t){ var num = arguments.length if (num == 0){ alert("preset stage"); setTimeout(function(){test(1,1)},2); } if (myTrig == 1){ alert("starting first recursion"); if (t==1.5 || t>1.5) { alert("exiting"); return ; } alert(myTrig); alert(t); t += 0.1; setTimeout(function(){test(1,t)},2); } if (myTrig == 2){ alert(myTrig); } } When this function is run clean like so test(); It passes trough a preset stage and then is passed on to the first recursive part of the code. if (myTrig == 1){ alert("starting first recursion"); if (t==1.5 || t>1.5) { alert("exiting"); return ; } alert(myTrig); alert(t); t += 0.1; setTimeout(function(){test(1,t)},2); Each time var t is incremented by 0.1. But not exactly, a 0.000000001 value is also added. Any JS magician care to explain? Quote Link to comment Share on other sites More sharing options...
Adam Posted March 12, 2010 Share Posted March 12, 2010 http://www.builderau.com.au/program/javascript/soa/Why-I-Love-ECMAScript-4-Real-Decimals/0,339028434,339289678,00.htm Quote Link to comment Share on other sites More sharing options...
Omirion Posted March 12, 2010 Author Share Posted March 12, 2010 An interesting read thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.