Answer the question
In order to leave comments, you need to log in
Why is no value returned from module in javascript in nodejs?
Hello.
I have 2 files:
test1.js
import JSBI from './jsbi.js';
console.log( JSBI.BigInt('TEST!') );
class JSBI extends Array {
static BigInt(arg) {
return arg;
}
}
export default { JSBI, BigInt };
Answer the question
In order to leave comments, you need to log in
When you export the { JSBI, BigInt } object as default in the jsbi.js file, you essentially exported the object outside:
{
JSBI: JSBI,
BigInt: BigInt
}
where BigInt is a standard JavaScript function that converts the passed argument to the BigInt type, then you import this whole object in the test1.js file, in fact the whole object
{
JSBI: JSBI,
BigInt: BigInt
}
is now stored in a JSBI variable, and when you call JSBI.BigInt, you call a non-static class method (to call it you need was to write JSBI.JSBI.BigInt() ), and you call the BigInt method which converts the argument to a type, which is why it swears, since the string cannot be converted to it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question