Last active
July 22, 2021 15:30
-
-
Save rajaramtt/080da6c5faab34c6e658c3331d9df119 to your computer and use it in GitHub Desktop.
Promise Code in 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
testFun(): void { | |
this.testPromise(identity).then(data => { | |
}).catch(function (e) { | |
console.log(e); | |
}); | |
} | |
private testPromise(identity): Promise<any> { | |
const outerThis = this; | |
return new Promise(resolve => { | |
resolve(); | |
}); | |
} | |
function loadData() { | |
return new Promise(function(resolve, reject) { | |
setTimeout(() => { | |
alert('hi'); | |
resolve("success") | |
}); | |
}); | |
} | |
loadData().then( | |
result => { | |
alert('hello') | |
}, | |
error => { | |
alert(error) | |
}); | |
/* Call Back */ | |
function loadData(callback) { | |
setTimeout(function() { | |
alert("hi"); | |
callback(); | |
}); | |
} | |
loadData(function() { | |
alert("hello"); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment