pjldesign
pjldesign

Reputation: 397

SCRIPT1003: Expected ':' in IE 11 only

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;
        }
    }
})()

Upvotes: 2

Views: 6871

Answers (1)

adeneo
adeneo

Reputation: 318212

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.org/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)

Upvotes: 4

Related Questions