哈希表并没有真正发挥作用

发布于 2024-09-18 09:24:25 字数 227 浏览 4 评论 0原文

我正在做一些网络开发,我想在我的代码中使用关联数组。我在其他设计工作中使用过哈希表,它们确实有效。

但是,当我尝试调用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无声无音无过去 2024-09-25 09:24:25

你可以说 var coms = {}var coms = new Object()

对象是 JS 中的哈希表

coms.something = 1 是一样的thing as coms["something"] = 1

括号表示法通常更常用于 JS 中的“哈希表”,因为它用于诸如 var coms = {"something": 1} 之类的关联 并在 Python 等语言中用于实际的哈希表/字典表示。

You can say var coms = {} or var coms = new Object()

Objects are hashtables in JS

coms.something = 1 is the same thing as coms["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.

你的呼吸 2024-09-25 09:24:25

有一个名为 jshashtable 的 JavaScript 哈希表实现,由我编写。与 JavaScript Object 不同,它允许任何对象用作键。

var h = new Hashtable();
var o = {};
h.put(o, "Some value");
h.put("foo", 23);
alert(h.get(o)); // "Some value"

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 h = new Hashtable();
var o = {};
h.put(o, "Some value");
h.put("foo", 23);
alert(h.get(o)); // "Some value"
仙女 2024-09-25 09:24:25

或者 var coms,就此而言

Or var coms, for that matter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文