您需要自己完成工作。在可能的第一时间阅读所有属性。从那时起,您可以将属性列表与静态列表进行比较。
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; }}
所以现在,我们可以像
// on initreadGlobalProps(); // store current properties on global object
然后
window.foobar = 42;findNewEntries(); // returns an array of new properties, in this case ['foobar']
当然,这里需要说明的是,您只能在脚本能够最早调用它的时候“冻结”全局属性列表。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)