获取所有用户自定义窗口的属性?

编程入门 行业动态 更新时间:2024-10-26 16:32:48
本文介绍了获取所有用户自定义窗口的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法找出在JavaScript中的所有用户定义的窗口属性和变量(全局变量)?

Is there a way to find out all user defined window properties and variables (global variables) in javascript?

我试过的console.log(窗口)但名单是无止境的。

I tried console.log(window) but the list is endless.

推荐答案

您需要做的工作为自己。阅读所有属性,在第一次的时间就可以了。从这一点上,你可以用静态的比较属性列表。

You would need to do the work for yourself. Read in all properties, on the first possible time you can. From that point on, you can compare the property list with your static one.

var globalProps = [ ]; function readGlobalProps() { globalProps = Object.getOwnPropertyNames( window ); } function findNewEntries() { var currentPropList = Object.getOwnPropertyNames( window ); return currentPropList.filter( findDuplicate ); function findDuplicate( propName ) { return globalProps.indexOf( propName ) === -1; } }

所以,现在,我们可以去像

So now, we could go like

// on init readGlobalProps(); // store current properties on global object

和后来

window.foobar = 42; findNewEntries(); // returns an array of new properties, in this case ['foobar']

当然,这里需要说明的是,你只能在那里你的脚本能够调用它的最早时间时间冻结在全球属性列表。

Of course, the caveat here is, that you can only "freeze" the global property list at the time where your script is able to call it the earliest time.

更多推荐

获取所有用户自定义窗口的属性?

本文发布于:2023-10-21 17:36:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   属性   窗口   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!