SCRIPT1003:仅在IE 11中使用的预期':'
问题描述:
我的脚本在每个浏览器中都能正常工作,但也就是11(当然就是...)。无法弄清楚我还能做些什么。 JS林特传递我的脚本...说它缺少冒号。这是整个功能。感谢任何见解。在开始“setcurrentList(list) {
”的行上发生错误(倒数第二个函数)。SCRIPT1003:仅在IE 11中使用的预期':'
编辑:更新现在的代码在最后一个函数接收错误:getcurrentList()
JQ
generateAllLocationsData = (function() {
var counter = 0;
if (typeof allLocationsData == "undefined") {
allLocationsData = [];
for (var x = 0; x < officesData.children.length; x++) {
for (var y = 0; y < officesData.children[x].departments.length; y++) {
if (officesData.children[x].departments[y].jobs.length > 0) {
for (z = 0; z < officesData.children[x].departments[y].jobs.length; z++) {
counter++;
ids.push(officesData.children[x].departments[y].jobs[z].id);
g_deptHolder[officesData.children[x].departments[y].jobs[z].id] = officesData.children[x].departments[y].name;
}
}
}
}
jobsData = jobsData.sort(function(a, b) {
if (a.title > b.title) {
return 1;
}
if (a.title < b.title) {
return -1
}
return 0;
});
for (var x = 0; x < jobsData.length; x++) {
var dept = g_deptHolder[jobsData[x].id]
if (typeof officesData["All Departments"][dept] == "undefined") {
officesData["All Departments"][dept] = [];
}
officesData["All Departments"][dept].push(jobsData[x]);
}
var sortedObject = [];
Object.keys(officesData["All Departments"]).sort().forEach(function(key) {
sortedObject[key] = officesData["All Departments"][key];
})
officesData.children = officesData.children.sort(function(a, b) {
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1
}
return 0;
})
officesData["All Departments"] = sortedObject;
}
console.log("sorted", officesData);
return officesData;
});
return {
isLoading: function() {
return (!jobsDataLoading && !officesDataLoaidng) ? false : true;
},
getJobsData: function() {
if (this.isLoading() == false) {
return officesData;
} else {
return false;
}
},
getOfficesData: function() {
if (this.isLoading() == false) {
return officesData;
} else {
return false;
}
},
getAllLocationsData: function() {
return generateAllLocationsData();
},
setcurrentList: function(list) {
this.currentList = list.sort(function(a, b) {
if (a.title < b.title) {
return -1;
}
if (a.title > b.title) {
return 1;
}
return 0;
});
},
getcurrentList(): function(list) {
return this.currentList;
}
}
})()
答
你的语法
setcurrentList(list) {
对象内,仅在ES2015有效的,并且是什么被称为方法定义,一种在对象文字中声明函数的简便方法
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions
方法的定义是无效的IE11,它应该是
setcurrentList: function(list) {
,如果你要支持旧的浏览器(或IE的任何版本)
呀,语法今年及未来item应该是'name:function(parameters)',但你的名字是'name(parameters)'。只需将'setcurrentList(list)'改为'setcurrentList:function(list)',并用'getcurrentList'修改相同... – cramopy
它应该是'setcurrentList:function(list){'...并且JSLint不会“通过”该代码。 – Pointy
[我在IE 11中得到了错误SCRIPT1003:Expected':'; (Java脚本代码错误)](https://stackoverflow.com/questions/46651124/i-get-the-error-script1003-expected-in-ie-11-java-script-code-error)(可能还有其他问题) – ASDFGerte