Implement a Promise class with then, catch, and state
You are tasked with implementing a custom Promise class in JavaScript, mimicking the behavior of the native Promise. This includes handling asynchronous operations, chaining methods, and error management. The Promises/A+ specification defines how a custom Promise in JavaScript should behave.
Your implementation should support the basic promise methods: then, catch, and the constructor should take an executor function with resolve and reject parameters.
Here’s an example of how your custom Promise might be used:
const promise = new MyPromise((resolve, reject) => {
setTimeout(() => resolve("Success!"), 1000);
});
promise.then(value => console.log(value));
Please make sure to include a method called getState() that returns the STATE to pass all unit tests.