gpt4 book ai didi

javascript - 为什么我的 OwnPropsEqualTrue 函数会破坏我的代码?

转载 作者:行者123 更新时间:2023-12-03 08:03:27 24 4
gpt4 key购买 nike

花了 3 个小时试图找到该消息的来源

Object doesn't support property or method 'exec'

我得到了,这会产生更多错误,我已将其范围缩小到我的函数

Object.prototype.OwnPropsEqualTrue = function ( )
{
var true_props = [];
for ( var this_prop in this )
{
if ( this.hasOwnProperty(this_prop) && this.this_prop === true )
{
true_props.push(this_prop);
}
}
return true_props;
}

作用于对象的是字符串到 bool 值的映射,例如

{ "SomeBoolean" : true, "SomeOtherBoolean" : false, "IsInChicago" : false } 

由于某种原因,此函数的存在导致了我提到的错误并指向

if(isCurrentExternalUser=isExternalUser(),isCurrentExternalUser&&BindClickOnO365SettingsMenu(),isBizStampingDlg=!1,window.location.href.indexOf("IsDlg=1")>-1&&(window.location.href.search(/Upload.aspx/i)>-1||window.location.href.search(/UploadEx.aspx/i)>-1)?(isBizStampingDlg=!0,isUploadDialog=!0):isUploadDialog=!1,window.location.href.indexOf("IsDlg=1")>-1&&window.location.href.search(/aclinv.aspx/i)>-1?(isBizStampingDlg=!0,isSharingDialog=!0):isSharingDialog=!1,isRightToLeft=$("html:first").attr("dir")=="rtl"?!0:!1,uiVersion==15||!isBizStampingDlg)

SharePoint 中 JavaScript 库的行。

任何人都可以尝试帮助我理解我在这里做错了什么吗?浏览器是 IE,顺便说一句。

最佳答案

如果您必须向对象原型(prototype)添加方法(您可能不应该),请使用Object.defineProperty添加它:

Object.defineProperty(Object.prototype, "ownTrueProperties", {
value: function() {
return Object.keys(this).filter(function(key) {
return this[key] === true;
}, this);
}
});

这将使该属性不可枚举,因此不会弄乱 for ... in 循环。

关于javascript - 为什么我的 OwnPropsEqualTrue 函数会破坏我的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34499781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com