使用“for ... in”的自托管 JavaScript 编辑器?

发布于 2024-11-02 19:48:02 字数 238 浏览 3 评论 0原文

我在想一件事,因为 for(var i in obj) 几乎可以枚举 DOM 或 javascript 对象内的任何东西,所以是否有任何自托管的 javascript 编辑器使用for ... in 提供语法自动建议、发现类属性/方法、外部 API?

Edit1:感谢大家的语法建议和不可枚举函数,但我正在寻找的是一个基于这个想法的编辑器

I am thinking of one thing, since for(var i in obj) can pretty much enumerate anything inside a DOM or javascript object, so are there any selfhosted javascript editor that use for ... in to offer grammar auto-suggest, discover class property/methods, external API?

Edit1: Thanks guys for the grammar suggestion and non-enumerable functions, but what I looking for is an editor based on this idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

丶视觉 2024-11-09 19:48:02

由于某些成员是不可枚举的,因此您必须使用 Object.getOwnPropertyNames,甚至稍微走一下原型链(使用 Object.getPrototypeOf)。这就是我的意思:

>>> Object.getOwnPropertyNames([]);
["length"]

>>> Object.getOwnPropertyNames(Array.prototype);
["length", "constructor", "toSource", "toString", "toLocaleString", ...]

Because some of the members would be non-enumerable, you'd have to use Object.getOwnPropertyNames, and even walk the prototype chain a bit (using Object.getPrototypeOf). Here's what I mean:

>>> Object.getOwnPropertyNames([]);
["length"]

>>> Object.getOwnPropertyNames(Array.prototype);
["length", "constructor", "toSource", "toString", "toLocaleString", ...]
め七分饶幸 2024-11-09 19:48:02

for(in) 只会提供可枚举的属性,不包括大多数函数。

不幸的是,很大一部分 DOM 是由不可枚举的函数而不是属性构成的,这意味着您的想法可能不会以任何有意义的方式发挥作用。对不起。 :(

这是一个类似的问题,有人询问有关枚举 window 对象:http://compgroups.net/comp.lang.javascript/Please-help-with-enumeating-functions-in-window-object

[编辑]

调试工具在各种浏览器中,例如 Firebug,它们在浏览器正常环境范围之外的级别上工作,这允许它们执行诸如查看不可枚举元素之类的操作,并且还可以跨越选项卡和域之间的边界。普通的浏览器范围是有限的,不能做这些事情,

所以如果你的计划是编写一个浏览器插件,那么你也许可以做到这一点,但这与将其编写为普通的 javascript 包含完全不同。在浏览器中。

for(in) will only give you enumeratable properties, which doesn't include most functions.

Unfortunately, a large proportion of the DOM is constructed of un-enumeratable functions rather than properties, meaning that your idea probably won't work in any meaningful way. Sorry. :(

Here's a similar question where someone asked about enumerating the window object: http://compgroups.net/comp.lang.javascript/Please-help-with-enumerating-functions-in-window-object.

[EDIT]

The debugging tools in various browsers, such as Firebug, work at a level outside the scope of the browser's normal environment. This allows them to do things such as see non-enumeratable elements, and also to cross the boundaries between tabs and domains. Scripts working within the normal browser scope are limited and cannot do these things.

So if your plan is to write a browser plug-in, then yes, you may be able to do this. However that is a different thing entirely to writing it as a normal javascript include in a browser.

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