javascript - Is it possible to pass the result of a promise as an argument to IIFE -
i have been refactoring old code uses iife fetch , initiate set of values.
var exampleinitiate = (function exampleinitiate(){ ..call backend service })();
now, per new requirement, have call same iife argument, , argument result of promise invoked later. understand iife invoked, , if result of promise, able call iife again? understands iifes run once only.
i thinking best not use iife here not fit here in case. correct, or there indeed way call iife passing argument value promise?
you can have couple of options if understand correct. first can pass argument iife this:
var mypromise = getpromise(); var exampleinitiate = (function exampleinitiate(promise){ promise.then(function() { ... }); ..call backend service })(mypromise);
but wouldn't call way clear. suggest erase iife , use promises do:
getsomebackendresponse().then(function (data) { ... })
edit: if iife returns promise yes, think can't pass in result of function again, since iife invoked once. rethink logic of chunk of code.
Comments
Post a Comment