您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

您需要自己完成工作。在可能的第一时间阅读所有属性。从那时起,您可以将属性列表与静态列表进行比较。

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']

当然,这里需要说明的是,您只能在脚本能够最早调用它的时候“冻结”全局属性列表。

其他 2022/1/1 18:13:50 有508人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶