indutny / bn.js

BigNum in pure javascript
MIT License
1.19k stars 150 forks source link

Child class extending BN, using BN in constructor #206

Open amaury1093 opened 5 years ago

amaury1093 commented 5 years ago
import BN from "bn.js";

class MyBN extends BN {
  doSomething() {
    console.log("HELLO");
  }
}

const a = new MyBN(new BN(123));
console.log(a.toString());  // this works, logs 123
a.doSomething();

Expected: Logs HELLO

Actual: Doesn't log anything on the doSomething line.

Repro: https://codesandbox.io/s/508mm5zz5l

Notes: Using typescript 3.0.1

fanatid commented 5 years ago

I think this is expected result, check constructor function: https://github.com/indutny/bn.js/blob/24cc2dd51b58694088a637a314689f61c9ba65a4/lib/bn.js#L22-L24