随笔分类 -  JavaScript代码小优化

摘要:if 优化写法 //普通写法 if (x 'abc' || x 'def' || x 'ghi' || x 'jkl') { //logic } //简写方法 if (['abc', 'def', 'ghi', 'jkl'].includes(x)) { //logic } //普通写法 if (x 阅读全文
posted @ 2022-07-11 09:58 前端搬运工bug 阅读(24) 评论(0) 推荐(0) 编辑
摘要:houseObj.listen = function(key,fn){ // if(!this.listen[key]){ // this.listen[key] = []; // }else{ // this.listen.push(fn); // } (this.listen[key] || ( 阅读全文
posted @ 2022-06-20 16:46 前端搬运工bug 阅读(22) 评论(0) 推荐(0) 编辑
摘要:// 优化前 app.get = function(){} app.post = function(){} app.put = function(){} // 优化后 var menthod = ['put','get','post']; menthod.forEach(function(key){ 阅读全文
posted @ 2022-06-20 16:45 前端搬运工bug 阅读(18) 评论(0) 推荐(0) 编辑
摘要:const el = document.getElementById('test'); el.style.cssText = `border-left:1px;padding:5px` 阅读全文
posted @ 2022-06-20 16:42 前端搬运工bug 阅读(17) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示