C
C
Cpa2018-02-16 22:39:32
JavaScript
Cpa, 2018-02-16 22:39:32

How to make callback?

I can’t understand how the callback is done correctly, it’s already the second day, well, I’m not catching up with it. Please help me with my code, how to do it right - first we display AAAAA then BBBBB. First we make the one function, then when it completes we execute two....

<script type="text/javascript">


var one = function(callback)
{

setTimeout('document.write("<h1>AAAAAAAAAAAAAAAA</h1>")', 1000);
callback;
}


var two = function()
{
document.write("<h1>BBBBBBBBBBBBBBBBB</h1>")
}

one(two);

</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-02-16
@GavriKos

Well, CALL callback is the same method. Parentheses...
Well, because of the timers, you will first have BBB, and then AAA. Why callbacks are here is not clear, but probably it should be so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question