Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jsbn.js BigInteger-如何使用普通数字进行实例化?_Javascript_Jquery_Biginteger_Jsbn - Fatal编程技术网

Javascript jsbn.js BigInteger-如何使用普通数字进行实例化?

Javascript jsbn.js BigInteger-如何使用普通数字进行实例化?,javascript,jquery,biginteger,jsbn,Javascript,Jquery,Biginteger,Jsbn,我尝试了两种方法: var a = new BigInteger(5); 及 但两者都给了我一个错误: TypeError: 'undefined' is not an object (evaluating 'b.nextBytes') bnpFromNumberjsbn2.js:126 您只能用字符串实例化吗?我本想给出一个更好的答案,但您没有提到您使用的是哪个BigInteger库 // Yes, use the two '..' var a = new BigInteger(5..to

我尝试了两种方法:

var a = new BigInteger(5);

但两者都给了我一个错误:

TypeError: 'undefined' is not an object (evaluating 'b.nextBytes')
bnpFromNumberjsbn2.js:126

您只能用字符串实例化吗?

我本想给出一个更好的答案,但您没有提到您使用的是哪个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);
  };

}());

谢谢,这很有帮助。在标题中我提到了jsbn.js,但我应该添加链接:实际上,看看它,新函数应该有两个参数——但这是一个非常简单的修复方法。
(function() {
  var oldConstructor = BigInteger;
  BigInteger = function(v) {
    if (typeof v === "number") {
      return oldConstructor(""+v);
    }
    return oldConstructor(v);
  };

}());