简体   繁体   English

WebIDL定义JS Number类型的无符号缩写

[英]WebIDL defines unsigned short to JS Number type

I read a document and it points out that WebIDL defines IDL unsigned short mapped to JS Number. 我阅读了一份文档,它指出WebIDL定义了映射到JS Number的IDL unsigned short。

The range of unsigned short is from 0 to 65535. JS Number can be -9007199254740992 to 9007199254740992. 无符号short的范围是0到65535。JS编号可以是-9007199254740992至9007199254740992。

This really confuses me since the big gape between these two definition. 由于这两个定义之间的巨大差距,这确实使我感到困惑。 Can anyone explain this? 谁能解释一下?

Thanks 谢谢

As mentioned by Loïc Faure-Lacroix, JS Numbers are much more complicated than unsigned short. 正如LoïcFaure-Lacroix所提到的,JS Numbers比unsigned short复杂得多。

JS has a few types: JS有几种类型:

Undefined – undefined
Boolean – false, true
Number – 0, -2.5, Infinity, NaN
String – "", "hello"
Object – { }, { "key": "value" }, [1, 2, 3], function() { }, /^regexp?$/

The point being here, is that when you define in your WebIDL a number, you need take into consideration what you'll need for precision and accuracy. 这里的要点是,当您在WebIDL中定义数字时,需要考虑对精度和准确性的要求。 So, if you're expecting to storage something bigger then an unsigned short, declare something like an unsigned int, that holds up to 4,294,967,295. 因此,如果您希望存储的内容比无符号的short大,则声明一个无符号的int,最多可容纳4,294,967,295。

The idea here is to not rely on JavaScript types, but on the WebIDL (which might be translated to Python, or C, or C++ or something). 这里的想法不是依靠JavaScript类型,而是依靠WebIDL(可以将其转换为Python,C,C ++或类似的东西)。

Hope I was able to clarify your question. 希望我能够澄清您的问题。 If not, I recommend that you poke @heycam at irc.mozilla.org, he knows it all :). 如果没有,我建议您在irc.mozilla.org戳@heycam,他知道这一切:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM