假设我有3个具有相同方法的对象,除了每个对象在setTimeOut中调用不同的CardPopup.method。另外,itemInfoHover1中的fetch方法传入了2个变量,但在itemInfoHover2和3中传递了3个变量。每个showVisiblePopup也有不同的变量。
我的问题是有没有办法将3个对象优化为一个,并在点击时只调用正确的对象?
我想也许使用数组文字和$ each,但我不知道如何正确地做到这一点。
var itemInfoHover1 = {
fetch : function(el, key){
showFlag = true;
$(el).mouseout(function(){
itemInfoHover1.hide();
});
clearTimeout(window.showtimeout);
window.showtimeout = window.setTimeout(function(){
CardPopup.GetCardPopupNew(el.id, key, cardInfoHover.show);
}, 100);
},
show: function (result) {
showVisiblePopup(itemInfoHover1, 'itemDetails', result.source, result.contents, false);
},
hide: function () {
hideVisiblePopup('itemDetails');
}
}
var itemInfoHover2 = {
fetch: function (el, key, item_id) {
showFlag = true;
$(el).mouseout(function () {
itemInfoHover2.hide();
});
clearTimeout(window.showtimeout);
window.showtimeout = window.setTimeout(function () {
CardPopup.GetSuggestedPriceInfo(el.id, key, item_id, itemInfoHover2.show);
}, 100);
},
show: function (result) {
showVisiblePopup(suggestedPriceInfo, 'priceDetails', result.source, result.contents, false);
},
hide: function () {
hideVisiblePopup('priceDetails');
}
}
var itemInfoHover3 = {
fetch: function (el, key, item_id) {
showFlag = true;
$(el).mouseout(function () {
itemInfoHover3.hide();
});
clearTimeout(window.showtimeout);
window.showtimeout = window.setTimeout(function () {
CardPopup.GetHistoricalSalesInfo(el.id, key, item_id, window.location.pathname, itemInfoHover3.show);
}, 100);
},
show: function (result) {
showVisiblePopup(suggestedPriceInfo, 'historyDetail', result.source, result.contents, false);
},
hide: function () {
hideVisiblePopup('historyDetail');
}
}