最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SCRIPT1003: Expected ':' in IE 11 only - Stack Overflow

programmeradmin2浏览0评论

My script works perfectly in every browser but ie 11 (of course ie...). Can't figure out what more I can do. JS Lint is passing my script... Says it's missing colon. Here's the entire function. Thanks for any insight at all. Error occurs on line that begins "setcurrentList(list) {" (second to last function).

Edit: updated code now receiving error on last function: 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;
        }
    }
})()

My script works perfectly in every browser but ie 11 (of course ie...). Can't figure out what more I can do. JS Lint is passing my script... Says it's missing colon. Here's the entire function. Thanks for any insight at all. Error occurs on line that begins "setcurrentList(list) {" (second to last function).

Edit: updated code now receiving error on last function: 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;
        }
    }
})()
Share Improve this question edited Oct 16, 2017 at 18:06 pjldesign asked Oct 16, 2017 at 17:39 pjldesignpjldesign 3971 gold badge5 silver badges17 bronze badges 5
  • Yeah, syntax for this and the next item should be name: function(parameters) but yours is name(parameters). Just change setcurrentList(list) to setcurrentList: function(list) and the same with getcurrentList... – cramopy Commented Oct 16, 2017 at 17:42
  • It should be setcurrentList: function(list) { ... and JSLint does not "pass" that code. – Pointy Commented Oct 16, 2017 at 17:42
  • Possible duplicate of I get the error SCRIPT1003: Expected ':' in IE 11; (Java Script Code error) (and probably other questions) – ASDFGerte Commented Oct 16, 2017 at 17:49
  • @Pointy yes I meant it passes that particular part of the code... Thanks – pjldesign Commented Oct 16, 2017 at 17:58
  • I am sorry. What was not working and what is working now? You have updated the code and it looks like the thing that was not working is not there anymore... :( – Naveed Butt Commented Jun 15, 2018 at 10:32
Add a ment  | 

1 Answer 1

Reset to default 4

Your syntax

setcurrentList(list) {

inside an object, is only valid in ES2015, and is what is called a method definition, a shorthand way to declare functions inside object literals

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions

Method definitions are not valid in IE11, it should be

setcurrentList: function(list) {

if you have to support older browsers (or any version of IE)

发布评论

评论列表(0)

  1. 暂无评论