Different methods based on Modernizr: click vs hover
问题 I want to be able to choose between .mouseover and .click events based on Modernizr's touch/no-touch output. if (Modernizr.touch) { $(el).click(stuff); $(el).click(stuff); } else { $(el).mouseover(stuff); $(el).mouseover(stuff); } But I don't want to write out all that stuff twice. Is it possible to define something so that I can just call: if (Modernizr.touch) {correctEvent = click} else {correctEvent = mouseover} $(el).correctEvent(stuff); $(el).correctEvent(stuff); 回答1: Yes, this is easy