哈希表并没有真正发挥作用
我正在做一些网络开发,我想在我的代码中使用关联数组。我在其他设计工作中使用过哈希表,它们确实有效。
但是,当我尝试调用“var coms = new Hashtable();”时,我收到错误消息,指出没有类哈希表。
我读过,在 JS 中,所有对象都是哈希表,所以我想如果我要定义一个空对象,并将其命名为 Hashtable,我会很高兴。我现在要尝试一下。不过,如果有人能告诉我如何调用官方哈希表,那就太好了。
I'm doing some web development, and I'd like to use an associative array in my code. I've used hashtables in other design work, and they definitely do the trick.
However, when I try to call "var coms = new Hashtable();", I get errors stating that there is no class hashtables.
I've read that in JS all objects ARE hashtables, so I suppose if I were to define an empty object, and name it Hashtable, I would be good to go. I'm going to try that n ow. However, it would be nice if someone could tell me how to call an official hashtable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以说
var coms = {}
或var coms = new Object()
对象是 JS 中的哈希表
coms.something = 1
是一样的thing ascoms["something"] = 1
括号表示法通常更常用于 JS 中的“哈希表”,因为它用于诸如
var coms = {"something": 1} 之类的关联
并在 Python 等语言中用于实际的哈希表/字典表示。You can say
var coms = {}
orvar coms = new Object()
Objects are hashtables in JS
coms.something = 1
is the same thing ascoms["something"] = 1
The bracket notation is usually more commonly used for "hashtables" in JS since it's used for associations like
var coms = {"something": 1}
and is used in languages like Python for the actual hashtable/dict representation.有一个名为 jshashtable 的 JavaScript 哈希表实现,由我编写。与 JavaScript
Object
不同,它允许任何对象用作键。There is a JavaScript hash table implementation called jshashtable, written by me. Unlike a JavaScript
Object
, it allows any object to be used as a key.或者
var coms
,就此而言Or
var coms
, for that matter