As I work on creating a user-script to incorporate a trailer video into a website, I encountered an issue with the callback function in my script. The goal is to filter the real source of the video from different URL formats, but for some reason, the callback just won't cooperate.
function test_url(preview,list,callback) {
if (list.length) {
preview.src = list[0][0];
}
preview.onerror = function() {
if (list.length) {
test_url(preview,list); // the function will be re-executed until the passed list is empty
}
else {
console.log('No more url available!');
if (callback && typeof(callback) === "function") { callback(); }
else {console.log('callback is : '+ typeof callback);}
return;
}
};
if (!list[0].length) {
list.splice(0,1);
}
else {
list[0].shift();
}}
test_url(Preview,URLs,function() {console.log('This is a callback.')})
The current problem persists with the callback showing that callback is undefined
.
The structure of the list provided looks like this:
[
['www.example1.com','www.example2.com'],
['www.example3.com','www.example4.com'],
['www.example5.com','www.example6.com']
]
As I navigate through this JavaScript challenge as a beginner, I am unsure where the hitch lies. Any insights or guidance would be greatly valued.