Спасибо тебе добрый человек. А можно сделать так чтобы возвращалось не значение цвета а функция. У меня есть test.js которая должна пройти без ошибок. Может с ней будет более понятно что мне нужно...
Вот она:
console.clear();
console.log('==Color Iterator Test==');
var test = function(msg, bool){
if(bool){
console.log("passed");
} else {
console.log("failed - "+msg);
}
};
var colorIter1 = AIS.colorIterator();
var colorIter2 = AIS.colorIterator();
test("return value not a function", typeof(colorIter1) === 'function');
// two cycles
test("color not correct", colorIter1() === '#48AEFF');
test("color not correct", colorIter1() === '#7FFFD4');
test("color not correct", colorIter1() === '#C00054');
test("color not correct", colorIter1() === '#87EF84');
test("color not correct", colorIter1() === '#DBA7F8');
test("color not correct", colorIter1() === '#EBC79E');
test("color not correct", colorIter1() === '#48AEFF');
test("color not correct", colorIter1() === '#7FFFD4');
test("color not correct", colorIter1() === '#C00054');
test("color not correct", colorIter1() === '#87EF84');
test("color not correct", colorIter1() === '#DBA7F8');
test("color not correct", colorIter1() === '#EBC79E');
for(var i = 0; i < 12; i++){
test("color not correct while iterating two iterators", colorIter1() === colorIter2());
};
А вот что получилось у нас за функция(ранее имена были немного другими):
var AISShipColors = ['#48AEFF', '#7FFFD4', '#C00054', '#87EF84', '#DBA7F8', '#EBC79E'];
var colorIterator = function(){
var fn = arguments.callee;
if (!("lastIndex" in fn) || fn.lastIndex >= AISShipColors.length) {
fn.lastIndex = 0;
}
return AISShipColors[fn.lastIndex++];
};
И первое что выдаётся в консоле это "return value not a function".
Благодарю!