JavaScript定义变量也和性能有关,看看下面的代码你就明白了,只是把变量声明换了个地方就可以让代码变快
//未优化的代码,很慢 for(var i = 0; i < 1000; i++){ var my_variable = 'This is my variable'; // Do something with my_variable } //优化后的代码,快 var my_variable; for(var i = 0; i < 1000; i++){ my_variable = 'This is my variable'; // Do something with my_variable }