JavaScript没有找到对象BigInteger

时间:2021-11-19 17:12:51

This is the first time I am trying to write javaScript.

这是我第一次尝试编写javaScript。

I have copied this code from the Internet

我从网上复制了这段代码

var polynomial = function( x ){
alert(x);
    x = new BigInteger( x.toString,10);
    var y = new BigInteger( coefficients[0].toString, 10 );
    for( var i = 1; i < k; i++ ){
        y = y.add( coefficients[i].multiply( x.pow( i ) ) );
    }
    return y;
};

However I get an error at the line

但是我在直线上得到了一个错误

x = new BigInteger( x.toString,10);

and I do not know why...

我不知道为什么……

Can anyone help me?

谁能帮我吗?

Thanks in advance

谢谢提前

3 个解决方案

#1


1  

As other people have pointed out, BigInteger is not built-in to JavaScript. I searched for a Big­Int­eger library in JavaScript and found this. To use that, you need to download jsbn.js and jsbn2.js from that website and add these script tags above the script tag including your script:

正如其他人指出的,BigInteger不是JavaScript内置的。我寻找一个大Int­­埃格尔在JavaScript库,发现这一点。要使用它,需要下载jsbn。js和jsbn2。来自该网站的js,并在脚本标签上面添加这些脚本标签,包括你的脚本:

<script type="text/javascript" src="jsbn.js"></script>
<script type="text/javascript" src="jsbn2.js"></script>

Additionally, as others have pointed out, you are missing parentheses on the toStrings.

另外,正如其他人所指出的,您在tostring上丢失了圆括号。

Together, your HTML might look like this:

总的来说,您的HTML可能是这样的:

<script type="text/javascript" src="jsbn.js"></script>
<script type="text/javascript" src="jsbn2.js"></script>
<script type="text/javascript">
    var polynomial = function(x) {
        x = new BigInteger( x.toString(), 10 );
        var y = new BigInteger( coefficients[0].toString(), 10 );
        for( var i = 1; i < k; i++ ){
            y = y.add( coefficients[i].multiply( x.pow( i ) ) );
        }
        return y;
    };
</script>

#2


1  

The BigInteger is not 1 of javascript types, I think that this part of code needs you to import a js framework, not sure what it is. You should check where you copy the code.

BigInteger不是javascript类型的1,我认为这部分代码需要您导入一个js框架,不确定它是什么。你应该检查你复制代码。

#3


0  

You are not calling the toString method!

您没有调用toString方法!

x.toString()  

The browser has a console, use F12

浏览器有一个控制台,使用F12

And it sounds like you did not include the library. https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js

听起来你没有包括图书馆。https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js

#1


1  

As other people have pointed out, BigInteger is not built-in to JavaScript. I searched for a Big­Int­eger library in JavaScript and found this. To use that, you need to download jsbn.js and jsbn2.js from that website and add these script tags above the script tag including your script:

正如其他人指出的,BigInteger不是JavaScript内置的。我寻找一个大Int­­埃格尔在JavaScript库,发现这一点。要使用它,需要下载jsbn。js和jsbn2。来自该网站的js,并在脚本标签上面添加这些脚本标签,包括你的脚本:

<script type="text/javascript" src="jsbn.js"></script>
<script type="text/javascript" src="jsbn2.js"></script>

Additionally, as others have pointed out, you are missing parentheses on the toStrings.

另外,正如其他人所指出的,您在tostring上丢失了圆括号。

Together, your HTML might look like this:

总的来说,您的HTML可能是这样的:

<script type="text/javascript" src="jsbn.js"></script>
<script type="text/javascript" src="jsbn2.js"></script>
<script type="text/javascript">
    var polynomial = function(x) {
        x = new BigInteger( x.toString(), 10 );
        var y = new BigInteger( coefficients[0].toString(), 10 );
        for( var i = 1; i < k; i++ ){
            y = y.add( coefficients[i].multiply( x.pow( i ) ) );
        }
        return y;
    };
</script>

#2


1  

The BigInteger is not 1 of javascript types, I think that this part of code needs you to import a js framework, not sure what it is. You should check where you copy the code.

BigInteger不是javascript类型的1,我认为这部分代码需要您导入一个js框架,不确定它是什么。你应该检查你复制代码。

#3


0  

You are not calling the toString method!

您没有调用toString方法!

x.toString()  

The browser has a console, use F12

浏览器有一个控制台,使用F12

And it sounds like you did not include the library. https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js

听起来你没有包括图书馆。https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js