javascript最优编码方案

字符串拼接最优方法
var liststring = "<li>"
var lis = []; 
for (var i = 100; i > 0; i--){    
  lis.push("This is list item #" + (99- i)); 
} 
liststring += lis.join("</li><li>") + "</li>";  
document.getElementById("someUL").innerHTML(liststring); 


遍历对象属性最优方法
for (var prop in someObject) {     
    if (someObject.hasOwnProperty(prop)) {         
        alert(someObject[prop]); // alert's value of property     
    } 
} 



绑定事件最佳方法

<div id="grid-container">    
    <a href="someimage.jpg"><img src="someimage-thumb.jpg"></a>    
    <a href="someimage.jpg"><img src="someimage-thumb.jpg"></a>    
    <a href="someimage.jpg"><img src="someimage-humb.jpg"></a>    
    ... 
</div> 

$("#grid-container").on("click", "a", function(event) {
    callLightbox(event.target); 
}); 


返回boolean值的最佳方法
return foo.toString() !== ""; 

你可能感兴趣的:(js,jquery)