🪟 Windows TippsMichael Linden wechselt zu Coda Audio Deutschland(15.09.2026 um 18:14 Uhr)
🤖 Android TippsMichael Linden wechselt zu Coda Audio Deutschland(15.09.2026 um 18:14 Uhr)
🕵️ SicherheitslückenCVE-2026-82431 | Apache Storm Nimbus authorization (CNNVD-2026-98874501)(15.09.2026 um 18:28 Uhr)
🪟 Windows TippsMichael Linden wechselt zu Coda Audio Deutschland(15.09.2026 um 18:14 Uhr)
🤖 Android TippsMichael Linden wechselt zu Coda Audio Deutschland(15.09.2026 um 18:14 Uhr)
🕵️ SicherheitslückenCVE-2026-82431 | Apache Storm Nimbus authorization (CNNVD-2026-98874501)(15.09.2026 um 18:28 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 5 Min Lesezeit
0

Inversion of Control in JavaScript Callbacks: Why Promises are the Answer

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. There are two ways in which the callback may be called: synchronous and asynchronous. It is the most fundamental async pattern in Javascript.



For example:





Everything works perfectly during testing. People start booking travel packages on your website, and everyone is happy with your work. Suddenly, one day, you get a call from your boss regarding a major issue. A customer booked a package and received four identical confirmation emails for one booking.



You start debugging the issue. You review the part of the code that sends the confirmation email, and everything seems correct. You then investigate further and find that the createBooking() utility from the third-party library called your callback function four times, resulting in four confirmation emails being sent.



You contact the third-party library’s support team and explain the situation. They tell you they have never encountered this issue before but will prioritize it and get back to you. After a day, they call you back with their findings. They discovered that an experimental piece of code, which was not supposed to go live, had caused the createBooking() function to call the callback multiple times.



The issue was on their side, and they assured you that it has been fixed. They apologized for the trouble and confirmed that the problem would not occur again.



To prevent any unwanted issue like that after some seeking for a solution, you implement a simple if statement like the following, which the team seems happy with:





Once a Promise is resolved (successfully completed), it stays that way forever — it becomes an immutable value at that point and can then be observed as many times as necessary. That means a resolved promise, its resolved value can be accessed or used multiple times in your code without affecting its state. This allows you to handle the result of the asynchronous operation in various parts of your application without worrying about the Promise changing or being re-evaluated.



Promises are a solution for the inversion of control issues that occur in callback-only code. Callbacks represent an inversion of control. So inverting the callback pattern is actually an inversion of inversion, or an uninversion of control. Restoring control back to the calling code where we wanted it to be in the first place.






References



Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
No Head in the Clouds! How Healthcare Providers Can Avert Cloud Security Breaches
1 Quelle
Magic Out-Of-The-Box — Does It Apply to SIEM Solutions?
1 Quelle
Vulnerability Assessment vs. Penetration Testing
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Inversion of Control in JavaScript Callbacks: Why Promises are the Answer

Thematisch verwandte Begriffe: Inversion, Control, JavaScript, Callbacks · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...