Here is my code:
Promise.all([
ajaxRequest(value, 'search/twitter', 'twitter').then(
function(res) {
var imgStatus = res[1].length > 0 ? "successfully.png" : "noRes.png";
$('.option_name_twitter + td').html("<img src='img/" + imgStatus + "' />")
optionsRes['twitter'] = res[1];
$('input.twitter').show();
}, function(err){
console.log(err);
$('.option_name_twitter + td').html("<img src='img/warning.png' />")
}
),
ajaxRequest(value, 'search/instagram', 'instagram').then(
function(res) {
var imgStatus = res[1].length > 0 ? "successfully.png" : "noRes.png";
$('.option_name_instagram + td').html("<img src='img/" + imgStatus + "' />")
optionsRes['instagram'] = res[1];
$('input.instagram').show();
}, function(err){
$('.option_name_instagram + td').html("<img src='img/warning.png' />")
}
)
]).then(() => {
stopBlinking()
formSubmited = false;
}).catch( (err) => {
console.error(err);
stopBlinking()
formSubmited = false;
})
As you see I have two functions into promise.all() method. Sometimes I need to call only one of those function separately. Something like this:
$("input.twitter").on('click', function(){
// only the first function should be called here
})
$("input.instagram").on('click', function(){
// only the second function should be called here
})
These ^ will be called after when Promise.all() is executed once. Because both input.twitter and input.instagram are hidden at first and will be shown after Promise.all() call.
So I want to initial those anonymous functions (which are exist at promise.all()) into variables, and use them on click of input.instagram and input.twitter. How can I do that?
var variable = function(){...}. use them on click,$('input').on('click', function(){ if($(this).hasClass(...)) {... }else if( $(this).hasClass(...)){...} }).thenor about theajaxRequestcalls?ajaxRequestajaxRequest(...)is a function call. "Anonymous function" usually refers to a function definition (without a name). E.g. the functions you pass to.thenare anonymous functions.