Looping through all of the items in the window object

℡╲_俬逩灬. 提交于 2019-12-05 07:28:24

In modern browsers Object.getOwnPropertyNames() and Object.getPrototypeOf() will help you get all properties of all objects in the prototype chain.

http://jsfiddle.net/FtVXN/

var obj = window;

do Object.getOwnPropertyNames(obj).forEach(function(name) {
       console.log(name);
   });
while(obj = Object.getPrototypeOf(obj));

If you want to see the separation of the prototype objects, then add a line that provides a divider.

http://jsfiddle.net/FtVXN/1/

var obj = window;

do {
    Object.getOwnPropertyNames(obj).forEach(function(name) {
        console.log(name);
    });
    console.log("=============================");
} while(obj = Object.getPrototypeOf(obj));

I do think I recall that in Firefox, some globals don't appear until you access them. You may need to do a little experimenting if you find that to be the case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!