-2
Whilest 워드 프로세서 읽기 : MDN Array forEach 나는 foreach 루프 내부의 인덱스를 얻으려고 노력하지만 그냥받지 못했습니다 ..자바 스크립트 foreach 루프 내부의 인덱스를 가져옵니다
var BANG = {};
BANG.boom = function (arr) {
this.array = arr;
this.start = function() {
Array.prototype.forEach.call(
this.array,
(function (blubb, index) {
window.setInterval(
this.hello(blubb, index),
1500
);
}).bind(this)
);
};
this.hello = function(blubb, index) {
alert(blubb, index)
};
};
xxx = new BANG.boom(['xxx', 'yyy', 'zzz']);
xxx.start();
어떻게 생각을 잘못하고있는거야?
"그냥 가져 오지 않는다"는 것은 무엇을 의미합니까? – zero298
네, ** ** 색인을 얻고 있습니다 : https://jsfiddle.net/9egp6qab/ 그냥 제대로 사용하지 않고 있습니다. [Mateusz의 대답] (http://stackoverflow.com/a/39595489/157247) 제대로 사용하는 방법을 보여줍니다. –