console.log(window.location.href + window.location.host)
//全局对象存储为局部对象减少全局查找
let _location = window.location;
console.log(_location.href + _location.host);
let book = {
title:\\\'this is title\\\',
desction:\\\'this is desction.\\\'
}
console.log(book.toString());//[object object]
function hasClassFn(element,className1,className2){
return element.className === className1 || element.className === className2;
}
//上面的代码中 element.className 被读取了两次。
//下面的代码将查找次数减少到了 1 次
function hasClassFn(element,className1,className2){
let currentClassName = element.className;
return currentClassName === className1 || currentClassName === className2;
}
原创文章,作者:小道研究,如若转载,请注明出处:https://www.sudun.com/ask/34506.html