首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在typescirpt中,有没有一种方法可以检查wasm中已经由typescirpt加载的值的类型,例如:I32?

在typescirpt中,有没有一种方法可以检查wasm中已经由typescirpt加载的值的类型,例如:I32?
EN

Stack Overflow用户
提问于 2019-10-04 00:57:25
回答 1查看 231关注 0票数 0

在WebAssembly中,我们有一个32位带符号的整数,如果我们加载这个i32,那么我们可以检查i32的类型?如果不能用javascirpt/i32检查类型,有没有其他方法来检查wasm的值?

所以我尝试构建wasm,typeof返回一个"number“

enter image description here

main.js

代码语言:javascript
复制
WebAssembly.instantiateStreaming(fetch("../out/main.wasm"), {
  main: {
    sayHello() {
      console.log("Hello from WebAssembly!");
    }
  },
  env: {
    abort(_msg, _file, line, column) {
      console.error("abort called at main.ts:" + line + ":" + column);
    }
  },
}).then(result => {
  const exports = result.instance.exports;
  const addResult = exports.add(19, 23);
  document.getElementById("container").textContent = "Result: " + exports.add(19, 23) + "Type:" + (typeof addResult);
}).catch(console.error);

那么,有没有其他方法来检查wasm的值呢?

EN

回答 1

Stack Overflow用户

发布于 2019-10-04 20:25:11

您可以使用typeof运算符

typeof运算符返回其操作数的数据类型,操作数可以是任何对象、函数或变量。

例如:

输入:typeof "raman"输出字符串

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58223739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档