如何使用来自 wasm 的 < > 运算符评估 js 值?

How to evaluate js values using < > operators from wasm?

Go 有一个 equal 方法来测试 JS 值之间的相等性。我们如何使用更大(或更少)的运算符来评估 js 值?我是否需要为此在 js 中编写一个 javascript 函数(即 function GT(a, b, op){return eval(a, op, b)})?

var a, b js.Value 

// test if a > b or b > a 

Value.Equal method is meant to test whether two js.Value 对象相等(与 javascript === 运算符相同)。

不受数字类型的限制。

相反,要执行比较,您需要获取类型化变量并比较它们。给定整数,您可以使用以下内容:

var a, b js.Value
// Get them from somewhere.

aint, bint := a.Int(), b.Int()

if a > b { ... }

请先检查 Value.Int() and others, they will panic if the conversion is not possible. Use Value.Type() 的文档,以确保您拥有预期的类型。