随笔分类 - JavaScript代码小优化
摘要:if 优化写法 //普通写法 if (x 'abc' || x 'def' || x 'ghi' || x 'jkl') { //logic } //简写方法 if (['abc', 'def', 'ghi', 'jkl'].includes(x)) { //logic } //普通写法 if (x
阅读全文
摘要:houseObj.listen = function(key,fn){ // if(!this.listen[key]){ // this.listen[key] = []; // }else{ // this.listen.push(fn); // } (this.listen[key] || (
阅读全文
摘要:// 优化前 app.get = function(){} app.post = function(){} app.put = function(){} // 优化后 var menthod = ['put','get','post']; menthod.forEach(function(key){
阅读全文
摘要:const el = document.getElementById('test'); el.style.cssText = `border-left:1px;padding:5px`
阅读全文