gpt4 book ai didi

javascript - Switch Case 在 IE 中抛出错误

转载 作者:行者123 更新时间:2023-11-28 12:32:17 26 4
gpt4 key购买 nike

下面是代码:

function addMethods(statusId) {
var methods = {};
if (typeof currentUser !== 'undefined') {
if (currentUser.isAdmin) {
switch(statusId) {
case "A":
methods.deactivate = true;
methods.delete = true;
methods.edit = true;
break;
case "P":
methods.activate = true;
methods.deactivate = true;
methods.delete = true;
methods.edit = true;
break;
case "D":
methods.activate = true;
methods.deactivate = true;
break;
case "I":
methods.activate = true;
methods.delete = true;
break;
default:
break;
}
} else if (currentUser.userBelongsToCompany) {
switch(statusId) {
case "A":
methods.deactivate = true;
break;
case "P":
methods.activate = true;
methods.deactivate = true;
methods.edit = true;
break;
case "I":
methods.activate = true;
break;
default:
break;
}
}
}

return methods;
}

错误:

SCRIPT1010: Expected identifier 

奇怪的是,当它尝试更新methods.delete时抛出错误:

function addMethods(statusId) {
var methods = {};
if (typeof currentUser !== 'undefined') {
if (currentUser.isAdmin) {
switch(statusId) {
case "A":
methods.deactivate = true;
methods.delete = true;

最佳答案

您使用关键字“delete”作为属性名称,但这实际上并不有效(在某些 JavaScript 环境中)。不过,您可以像这样编写代码:

    methods["delete"] = true;

关于javascript - Switch Case 在 IE 中抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20859280/

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