I created an inheritance class,such as:
class NumberTest extends Number{
constructor(numeric:number){
super(numeric);
}
}
Then I want to call the valueof method from an instance of NumberTest ,such as:
const numberTest=new NumberTest(4);
numberTest.valueOf();
But unlucky,throw an error,as follow:
TypeError: Number.prototype.valueOf requires that 'this' be a Number
at NumberTest.valueOf (<anonymous>)
in the javascript,I created the same code,like this:
class NumberTest extends Number{
constructor(numeric){
super(numeric);
}
}
It works well.
I think Number.prototype.valueOf method using the typeof judge it。so object type not number type。also this,I think this is a bug。 Shape up should extends base function。
I created an inheritance class,such as:
Then I want to call the valueof method from an instance of NumberTest ,such as:
But unlucky,throw an error,as follow:
in the javascript,I created the same code,like this:
It works well.
I think
Number.prototype.valueOfmethod using thetypeofjudge it。soobjecttype notnumbertype。also this,I think this is a bug。 Shape up should extends base function。