全局:");vart=newDate();for(v" />

JavaScript中全局变量、函数内变量以及常量表达式

标签:活动介绍    日期:2018-08-09 09:52    录入:美娱国际平台注册    浏览:

  var r, s="this is a very very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string", x=/^\s+|\s+$/g;  document.writeln("字符串测试  ");  (function(){  document.write("全局->全局:");  var t=new Date();  for(var i=0; i < 3000000; i++){  r=s;  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("全局->本地:");  var s=window.s;  var t=new Date();  for(var i=0; 美娱国际 i < 3000000; i++){  r=s;  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("常量->本地:");  var r;  var t=new Date();  for(var i=0; i < 3000000; i++){  r="this is a very very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string";  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("属性->本地:");  var r;  var s={ 0: window.s };  var t=new Date();  for(var i=0; i < 3000000; i++){  r=s[0];  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("本地->本地:");  var r;  var s=window.s;  var t=new Date();  for(var i=0; i < 3000000; i++){  r=s;  }  document.write(new Date() - t);  document.writeln("  ");  })();  document.writeln("正则表达式测试  ");  (function(){  document.write("全局->全局:");  var t=new Date();  for(var i=0; i < 3000000; i++){  r=x;  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("全局->本地:");  var x=window.x;  var t=new Date();  for(var i=0; i < 3000000; i++){  r=x;  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("常量->本地:");  var r;  var t=new Date();  for(var i=0; i < 3000000; i++){  r=/^\s+|\s+$/g;  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("属性->本地:");  var r;  var x={ 0: window.x };  var t=new Date();  for(var i=0; i < 3000000; i++){  r=x[0];  }  document.write(new Date() - t);  document.writeln("  ");  })();  (function(){  document.write("本地->本地:");  var r;  var x=window.x;  var t=new Date();  for(var i=0; i < 3000000; i++){  r=x;  }  document.write(new Date() - t);  document.writeln("  ");  })();  

★★★小编:美娱国际 整理文章,欢迎大家转载 ★★★
相关文章阅读