Web

Promise

Në shqip: Premtim

ShpjegimiSQ

Promise-i në JavaScript është një objekt që përfaqëson një rezultat që do të vijë më vonë — ose me sukses, ose me gabim. Me .then() thua çfarë të bëhet kur të vijë rezultati.

EnglishEN

A Promise in JavaScript is an object representing a result that will arrive later — either successfully or with an error. With .then() you say what to do when the result arrives.

Si ta mendosh

Si kuponi me numër në një fast food: ende s'e ke burgerin, por kuponi „premton“ që do ta marrësh — ose do të të thonë që ka mbaruar.

Lexoje në anglisht

Like the numbered receipt at a fast-food place: you don't have your burger yet, but the receipt “promises” you'll get it — or they'll tell you it's sold out.

Shembull kodijavascript

fetch("https://api.example.com/moti")  // kthen një Promise
  .then((pergjigja) => pergjigja.json())
  .then((moti) => console.log(moti))
  .catch(() => console.log("Diçka shkoi keq"));

Terma të lidhur