JSBI.BigInt ({ num: 2, [Symbol.toPrimitive]: function () {return this.num} });
Throws, Cannot read properties of undefined (reading 'num')
Because in JSBI.__toPrimitive, the object's toPrimitive method is first stored in a local var, and then called using that var. This means this is bound to undefined, and not the object.
The following
JSBI.BigInt ({ num: 2, [Symbol.toPrimitive]: function () {return this.num} });
Throws,
Cannot read properties of undefined (reading 'num')
Because in
JSBI.__toPrimitive
, the object's toPrimitive method is first stored in a local var, and then called using that var. This meansthis
is bound toundefined
, and not the object.