0

Problem in javascript ☹️

My code won't Run in Safari browser Problem line 24 const images = document.querySelectorAll("[data-src]"); function preloadImage(img) { const src = img.getAttribute("data-src"); if (!src){ return; } img.src = src; } const imgOptions = { threshold: 0, rootMargin: "0px 0px 300px 0px" }; /// Problem Line 24 const imgObserver = new IntersectionObserver((entries,imgObserver) => { entries.forEach(entry => { if (!entry.isIntersecting){ return; } else { preloadImage(entry.target); imgObserver.unobserve(entry.target); } Can any body Fix this?

1st May 2020, 9:17 AM
shayan
shayan - avatar
7 Answers
+ 2
That's your browser/Js engine doesn't support the arrow function ES6 feature... you should rewrite it with "classic" (explicit -- full typed "function() {}" format) function declaration or expression ;)
1st May 2020, 11:41 AM
visph
visph - avatar
+ 2
Where is your code, can you prepare your attempt here on playground please
1st May 2020, 10:41 AM
JaScript
JaScript - avatar
+ 2
tnx visph 👌🏻🙏🏻
1st May 2020, 11:55 AM
shayan
shayan - avatar
+ 1
And what say exactly the error message(s)? I guess it's not "problem line 24" or "problem line 18" without more details ;P Anyway, all what we could guess here, that 's you're probably missing the library providing the definition of IntersectionObserver, either because you don't or bad link it, or the ressource is unavailable for some reason (could be because you run your code in https but you link a js file trough http -- secure vs not secure requests ^^)
1st May 2020, 11:30 AM
visph
visph - avatar
0
i'm not javascript Developer This is all code of loder.js file const images = document.querySelectorAll("[data-src]"); function preloadImage(img) { const src = img.getAttribute("data-src"); if (!src){ return; } img.src = src; } const imgOptions = { threshold: 0, rootMargin: "0px 0px 300px 0px" }; /// Problem Line 24 const imgObserver = new IntersectionObserver((entries,imgObserver) => { entries.forEach(entry => { if (!entry.isIntersecting){ return; } else { preloadImage(entry.target); imgObserver.unobserve(entry.target); }
1st May 2020, 11:03 AM
shayan
shayan - avatar
0
if you open this code in notpad++ the problem is in line 18
1st May 2020, 11:04 AM
shayan
shayan - avatar
0
error is Syntaxerror : Unexpected tokan '=>'
1st May 2020, 11:37 AM
shayan
shayan - avatar