开发者

Self-hosted javascript editor using `for ... in`?

开发者 https://www.devze.com 2023-02-28 01:04 出处:网络
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 gra

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.


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", ...]


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消