ReferenceError: Strict mode forbids implicit creation of global property in for loop on promise

♀尐吖头ヾ 提交于 2020-01-07 09:25:38

问题


I am having a really strange problem. I am trying to perform a for loop on a promise return value. When I run the code from a jasmine test it breaks. When I run it from a browser it breaks. The code is....

courseService.getCourseDates(8).then(function (data) {

            console.log(data[0]);  --this works
            console.log(data[1]);  --this works

            for (s in data) {
                console.log(data[s]);
            }
}

Expected output:

'2014-06-14T00:00:00'
'2014-06-14T00:00:00'
'2014-06-14T00:00:00'
'2014-06-14T00:00:00'

Actual output from Karma/Jasmine:

ReferenceError: Strict mode forbids implicit creation of global property 's'

Actual Output from browser:

ReferenceError: s is not defined

Anyone know what is wrong? I have used for loops like this in the past and clearly the array is being populated okay....


回答1:


Try this:

for (var s in data) {
    ...
}


来源:https://stackoverflow.com/questions/23549062/referenceerror-strict-mode-forbids-implicit-creation-of-global-property-in-for

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!