Skip to content

Instantly share code, notes, and snippets.

View Sandeepv68's full-sized avatar
🏠
Working from home

Sandeep Vattapparambil Sandeepv68

🏠
Working from home
View GitHub Profile
@Sandeepv68
Sandeepv68 / promise1.js
Created November 25, 2020 18:17 — forked from vkarpov15/promise1.js
Write Your Own Node.js Promise Library from Scratch, Part 1
class MyPromise {
constructor(executor) {
if (typeof executor !== 'function') {
throw new Error('Executor must be a function');
}
// Internal state. `$state` is the state of the promise, and `$chained` is
// an array of the functions we need to call once this promise is settled.
this.$state = 'PENDING';
this.$chained = [];
// Create "backend" object to hold data for getters and setters on main object
const _ = Object.create( null );
Object.defineProperties(
_,
{
firstname: {
value: 'John',
writable: true,
enumerable: false,