【发布时间】:2016-03-12 18:02:29
【问题描述】:
我的项目的两个不同功能中有两段相似的代码 我想摆脱重复的代码。我该怎么做?
1:
getArray("my-hand").forEach(function(elem){
$(elem).mouseover(function(){
$(this).css({'top': '1em'});
});
$(elem).mouseout(function(){
$(this).css({'top': '0em'});
});
$(elem).click(function(){
var cardNode = $(this).get(0);
//some jquery animation
play(cardNode,time);
});
})
还有第二个
2:
getArray("my-hand").forEach(function(elem){
$(elem).mouseover(function(){
$(this).css({'top': '1em'});
});
$(elem).mouseout(function(){
$(this).css({'top': '0em'});
});
$(elem).click(function(){
var cardNode = $(this).get(0);
//a function with another jquery animation
validateCardAndAddForCollection(checkNumber,cardNode,time);
});
})
【问题讨论】:
标签: javascript jquery reusability