Answer the question
In order to leave comments, you need to log in
How to get the result of an asynchronous function in Javascript?
There is one asynchronous function. that extracts something. This is how it is used:
getSomeItems(
function( someItems ) {
/someItems - полученное(или получаемое?) нечто
/тут можно сделать что-то с этим нечто
}
);
getSomeItems(
function( someItems ) {
return someItems
}
);
Answer the question
In order to leave comments, you need to log in
And the old grandfather way
var mySomeItems = null;
getSomeItems(
function( someItems ) {
mySomeItems = someItems;
}
);
if(mySomeItems)
{
...
}
var myME = new ManagerEvents(...); // <-- где-то
myME.on("NewSomeItems", function(event)
{
var someItems = event.data;
...
});
getSomeItems(
(function( someItems )
{
this.emit("NewSomeItems", someItems);
}).bind(myME)
);
var myME = new ManagerEvents(...); // <-- где-то
myME.on("NewSomeItems", function(event)
{
var someItems = event.data;
...
});
getSomeItems(myME); // просто принимает аргументом ManagerEvents и внутри генерирует событие.
ManagerEvents.prototype.delegate = function(name)
{
var me = this;
return function()
{
return me.emit(name, arguments);
};
};
var myME = new ManagerEvents(...); // <-- где-то
myME.on("NewSomeItems", function(event)
{
var someItems = event.data[0];
...
});
getSomeItems(myME.delegate("NewSomeItems"));
Just return - no way, for this reason, the callback is passed to it. All subsequent logic will have to be implemented through it.
You can return a Promise .
In the future it will be possible to use generators .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question