I have this custom simple class:
class U8a extends Uint8Array {
logMe() {
return this.subarray(0);
}
}
And I ran this code:
const u = new U8a([1, 2, 3]);
console.log(u.logMe());
Expected result:
Uint8Array [ 1, 2, 3 ]
Actual result:
U8a [Uint8Array] [ 1, 2, 3 ]
Is it possible to return the result as an Uint8Array only?
u instanceof Uint8Array => trueyou just extend so the u is Uint8Array objectu.logMe().logMe(). I want to disable this.Uint8Array? That's not what it is: "Thesubarray()method returns a newTypedArrayon the sameArrayBufferstore and with the same element types as for thisTypedArrayobject." Plus it'd make your logging explicitly incorrect. You could use#fromand create a new array.