Is there a Javascript equivalent of Ruby's andand?

In trying to make my Javascript unobtrusive, I'm using `onLoad`s to add functionality to ``s and such. With Dojo, this looks something like: var coolInput = dojo.byId('cool_input'); if(coolInput) { dojo.addOnLoad(function() { coolInput.onkeyup = function() { ... }; }); } Or, approximately equivalently: dojo.addOnLoad(function() { dojo.forEach(dojo.query('#cool_input'), function(elt) { elt.onkeyup = function() { ... }; }); }); Has anyone written an implementation of Ruby's [andand][1] so that I could do the following? dojo.addOnLoad(function() { // the input's onkeyup is set iff the input exists dojo.byId('cool_input').andand().onkeyup = function() { ... }; }); or dojo.byId('cool_input').andand(function(elt) { // this function gets called with elt = the input iff it exists dojo.addOnLoad(function() { elt.onkeyup = function() { ... }; }); }); [1]: http://github.com/raganwald/andand/tree/master

以上就是Is there a Javascript equivalent of Ruby's andand?的详细内容,更多请关注web前端其它相关文章!

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

评论 抢沙发

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

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

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏