# One does not simply extend Promise

**URL:** <https://es.discourse.group/t/one-does-not-simply-extend-promise/1627>\
**Category:** Spec Reading\
**Created:** [March 3, 2023, 8:37am UTC](https://es.discourse.group/t/one-does-not-simply-extend-promise/1627 "2023-03-03T08:37:13Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![WebReflection](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/webreflection/32/248_2.png) [@WebReflection](https://es.discourse.group/u/WebReflection)\
**Post date:** [March 3, 2023, 7:29pm UTC](https://es.discourse.group/t/one-does-not-simply-extend-promise/1627/13 "2023-03-03T19:29:16Z")

</div>

In practice, I think this is very hard to explain out there:

```javascript
const sideEffect = {
  get value() {
    return Math.random();
  }
};

class Sub extends Promise {
  constructor(callback) {
    // expected callback invoke *once* up there
    super((resolve, reject) => {
      console.log(sideEffect.value);
      callback(resolve, reject);
    });
  }
}

class SubSub extends Sub {
  constructor(callback) {
    // expected callback invoke *once* up there
    // because super calls it once, expected max 2 invokes
    super((resolve, reject) => {
      console.log(sideEffect.value);
      callback(resolve, reject);
    });
  }
}

// expected 2 Math.random()
new SubSub(Object).then(Object) instanceof SubSub;
// true ... but ...

// got 4 Math.random()
// 0.8782228881162686
// 0.6226237763466325
// 0.8762779980398552
// 0.6806218405445226

```

As summary: shouldn't the constructor callback, for same constructor that derives its own thenable, trigger the callback never more than once? If not, what's the practical use case that supports current state of affairs? and why is defaulting to the super species is the only way to solve this?

Moreover: why a _then()_ should involve its constructor ever, when it's a branched derived promise of what its constructor did **once**?

---

_[View the full topic](https://es.discourse.group/t/one-does-not-simply-extend-promise/1627)._
