Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Initialisation {
- constructor() {
- this.aFunctionThatThrowsImmediately();
- this.aFunctionThatThrowsLater();
- }
- // Fake stuff to show the return values of module
- aFunctionThatThrowsImmediately() {
- console.log(this.errorCallback()); // error thrown, but platform not set
- }
- aFunctionThatThrowsLater() {
- setTimeout(() => {
- console.log(this.errorCallback()); // error found: platform-arbitrary-id
- }, 1000);
- }
- async getPlatform () {
- return "platform-arbitrary-id";
- }
- // Set a default no-op errorCallback (in case error is thrown)
- errorCallback() {
- return "error thrown, but platform not set"
- }
- // Expose a setter for platform
- setErrorCallback(errorCallback) {
- this.errorCallback = errorCallback;
- }
- }
- class Error {
- constructor(getPlatform) {
- this.setPlatform(getPlatform);
- }
- async setPlatform(getPlatform) {
- this.platform = await getPlatform();
- }
- onError() {
- return `error found: ${this.platform}`;
- }
- }
- const initInstance = new Initialisation();
- const errorInstance = new Error(initInstance.getPlatform);
- initInstance.setErrorCallback(errorInstance.onError.bind(errorInstance));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement