我试过了两个:
var a = new BigInteger(5);
并且
var b = new BigInteger(5, 10);
但两人都给我错误:
TypeError: 'undefined' is not an object (evaluating 'b.nextBytes')
bnpFromNumberjsbn2.js:126
你能用字符串实例化吗?
答案 0 :(得分:0)
我想提供更好的答案,但您没有提及您正在使用的WHICH BigInteger库。
// Yes, use the two '..'
var a = new BigInteger(5..toString());
// Of if you have a variable
var v = 10;
var a = new BigInteger(v.toString());
现在,凭借这些知识,您可以覆盖BigInteger
(function() {
var oldConstructor = BigInteger;
BigInteger = function(v) {
if (typeof v === "number") {
return oldConstructor(""+v);
}
return oldConstructor(v);
};
}());