测试代码如下:
<html> <script> var count = 0; var number = 1000; var globalArray = []; for (var i = 0; i < 900; i++) { var buggyObject = { callAgain: function() { var ref = this; var val = setTimeout(function() { ref.callAgain(); if( count > 3) number = 10000; for( var a = 0; a < number; a++) globalArray.push(a); console.log("called"); count++; }, 1000); // end of val declaration } // end of call again } // end of object declaration } buggyObject.callAgain(); </script> </html>