原生 js 获取 html 是一个 HTML Collection 集合,使用 let 方法可以获得块级作用域

var aCollection = document.getElementsByClassName("a");
for(var i=0; i<aCollection.length; i++){
        if(aCollection[i].href == String(window.location)){
                aCollection[i].className = "current";//此时this的作用域,仍是全局作用域,根本获取不到。
        }
}

var aCollection = document.getElementsByClassName("a");
for(let i=0; i<aCollection.length; i++){
        if(aCollection[i].href == String(window.location)){
                aCollection[i].className = "current";//此时this的作用域,是块级作用域,正常。
        }
}