您需要自己完成工作。在可能的第一时间阅读所有属性。从那时起,您可以将属性列表与静态列表进行比较。
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 init
readGlobalProps(); // store current properties on global object
然后
window.foobar = 42;
findNewEntries(); // returns an array of new properties, in this case ['foobar']