How to explain callbacks in plain english? How are they different from calling one function from another function?

后端 未结 30 1915
时光说笑
时光说笑 2020-11-22 11:13

How to explain callbacks in plain English? How are they different from calling one function from another function taking some context from the calling function? How can thei

30条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 11:23

    Think of a method as giving a task to a coworker. A simple task might be the following:

    Solve these equations:
    x + 2 = y
    2 * x = 3 * y
    

    Your coworker diligently does the math and gives you the following result:

    x = -6
    y = -4
    

    But your coworker has a problem, he doesn't always understand notations, such as ^, but he does understand them by their description. Such as exponent. Everytime he finds one of these you get back the following:

    I don't understand "^"
    

    This requires you to rewrite your entire instruction set again after explaining what the character means to your coworker, and he doesn't always remember in between questions. And he has difficulty remembering your tips as well, such as just ask me. He always follows your written directions as best he can however.

    You think of a solution, you just add the following to all of your instructions:

    If you have any questions about symbols, call me at extension 1234 and I will tell you its name.
    

    Now whenever he has a problem he calls you and asks, rather than giving you a bad response and making the process restart.

提交回复
热议问题