桥接模式 优化代码重复性

// 优化前
app.get = function(){}
app.post = function(){}
app.put = function(){}
// 优化后
var menthod = ['put','get','post'];
menthod.forEach(function(key){
  app[key] = function(){
    router[key].call(this);
  }
})

 

posted @ 2022-06-20 16:45  前端搬运工bug  阅读(15)  评论(0编辑  收藏  举报