摘要:
for-in loops are often incorrectly used to loop over the elements in an Array. This is however very error prone because it does not loop from 0 to length - 1 but over all the present keys in the object and its prototype chain. Here are a few cases where it fails:function printArray(arr) { for (var . 阅读全文
摘要:
Google的编程样式指南,原文地址:http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#varvar :When you fail to specify var, the variable gets placed in the global context, potentially clobbering existing values. Also, if there's no declaration, it's hard to tell in what scope 阅读全文