Refactor two jQuery UI auto-completes to be more Functional & DRY

I have two jQuery UI auto-completes on the same page and I'd like to make the code more "functional" and terse. My background is almost strictly OO and I'd like to get more serious about writing more functional JavaScript. Both of these functions are properties of an object literal that I'm using to namespace the functions on the page. Right now there is a lot of code that's repeated between the functions and I'd like to use something similar to the "[partial application][1]" pattern to reduce the code. autocomplete 1: initProject : function(){ var selected = 0; var suggestions = []; var projs; var len; $("#projectNum").autocomplete({ source : function(req, add){ $.getJSON("" + req.term, function(data){ //clear the suggestions array suggestions = []; projs = data[0]; len = projs.length; for(var i = 0; i

以上就是Refactor two jQuery UI auto-completes to be more Functional & DRY的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准