为了账号安全,请及时绑定邮箱和手机立即绑定

在 Postman 中使用 math.js

在 Postman 中使用 math.js

PIPIONE 2023-07-06 11:07:55
math.js我正在尝试在邮递员中使用。所以,在一个请求中我有postman.setGlobalVariable("mathjs", () => {   \\ The full math.js library });然后在应该使用该库的请求中我评估全局变量eval(globals.mathjs)();我不经常使用 JavaScript,所以也许我缺少一些基本的东西。在第一个请求中定义了一个全局变量mahjs,该变量的值是调用库代码的 lambda。然后,在第二个请求中,调用该 lambda 函数。如果到目前为止我的理解不正确,请纠正我。问题:之后如何调用库定义的函数?我已经尝试过:math.multiply(x,y);、Math.multiply(x,y);、multiply(x,y);。它们都无效。该函数multiply 似乎是由库定义的,并用作math.multiply(array, matrix) .与我已经做出的复用工作的比较。在一个请求中postman.setGlobalVariable("utils", () => {  myfunction = function (x){    return x+1;  };});并在使用它的请求中eval(globals.utils)();x = 1;console.log(myfunction(x));
查看完整描述

1 回答

?
尚方宝剑之说

TA贡献1788条经验 获得超4个赞

这解决了你的问题:


const mathjsUrl = "https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.5.1/math.min.js";


pm.sendRequest(mathjsUrl, (err, response) => {

    const mathjs = response.text();


    (new Function(mathjs))();

        let result = math.multiply(4,3);;

        console.log(result);

});


查看完整回答
反对 回复 2023-07-06
  • 1 回答
  • 0 关注
  • 74 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信