Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

javascript - 未定义“功能”(“Function” Is Not Defined)

Im trying to make a slider that changes images every 5 secondes.

(我正在尝试制作一个每5秒更改一次图像的滑块。)

But in console it says "changemementImages is not defined at new slider"

(但是在控制台中它说“ changemementImages未在新滑块上定义”)

 //change images every 5 sec this.temps = setInterval(changemementImages, 5000); this.image5Sec = changemementImages =()=>{ if(this.i >= 2){ this.i-=3; document.getElementById("images").src = this.slide[this.i]; } else if (this.i = 0){ document.getElementById("images").src = this.slide[++this.i]; } } 

  ask by Gobi translate from so


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Arrow functions need to be initialized before using them unlike declared functions.

(与声明的函数不同,箭头函数需要在使用之前进行初始化。)

https://developer.mozilla.org/en-US/docs/Glossary/Hoisting

(https://developer.mozilla.org/zh-CN/docs/Glossary/Hoisting)

Try to initialize changemementImages before setInterval.

(尝试在setInterval之前初始化changemementImages。)

const changemementImages =()=>{
   if(this.i >= 2){
       this.i-=3;
       document.getElementById("images").src = this.slide[this.i];
   }
   else if (this.i = 0){
       document.getElementById("images").src = this.slide[++this.i];
   }

}

this.temps = setInterval(changemementImages, 5000);

this.image5Sec = changemementImages;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...