Created
January 17, 2022 11:24
-
-
Save RiansyahTohamba/1aab017cb54912c9e81be9b3a8cebfbc to your computer and use it in GitHub Desktop.
example of promise.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getProducts(url){ | |
const promise = new Promise((resolve,reject) => { | |
const data = getData(url); | |
if(data.isExist()){ | |
resolve(data.to_json()); | |
}else{ | |
reject("error"); | |
} | |
}) | |
return promise; | |
} | |
const products = getProducts('https://61d8315de6744d0017ba89a2.mockapi.io/api/v1/products'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment