我有 10 个这样的功能:
function instagram_ajax(){
return ajaxRequest('search/instagramid', 'instagramid').then(
function(res) {
var imgStatus = res[1].length > 0 ? "checked_successfully.png" : "checked_noRes.png";
$('.option_name_instagramid + td').html("<img src='img/" + imgStatus + "' />")
optionsRes['instagramid'] = res[1];
}, function(err){
$('.option_name_instagramid + td').html("<img src='img/warning.png' />")
}
);
}
function googleplus_ajax(){
return ajaxRequest('search/googleplusid', 'googleplusid').then(
function(res) {
var imgStatus = res[1].length > 0 ? "checked_successfully.png" : "checked_noRes.png";
$('.option_name_googleplusid + td').html("<img src='img/" + imgStatus + "' />")
optionsRes['googleplusid'] = res[1];
}, function(err){
$('.option_name_googleplusid + td').html("<img src='img/warning.png' />")
}
);
}
.
.
.
如您所见,这些功能几乎是等价的,只是不同的是单词instagram
, googleplus
。我还有一个包含所有这些名称的数组:
var parts = ['instagram', 'googleplus', 'linkedin', 'facebook', ...];
现在我想知道,是否可以动态地制作这些数组?我的意思是将一个变量基函数放入一个循环中并使用该数组来制作所有这些函数?这样的事情可能吗?