I'd like to give this a try, but I have no experience at all with JS. I know HTML and CSS, as well as some PHP (enough to get by with small projects), but I have been avoiding JS forever.
Once I include the script in the <head> of an HTML document, how do I execute it? I guess I need to call the function "connect" from withing the <body> element? Do I need to give it some parameters (relayurl, filter, cb)? And what values should they have?
Sorry for asking so many questions but, as I said, I have no knowledge of JS at all, but I'm excited to try this script.
The code OP provided can be included as a whole inside the body tag, or. really anywhere in the html document. as you can see, the function connect is declared on line 2, and then called on line 15. which means it will start running as soon as the page is loaded.
when the events fire, the callback function gets called. the callback function gets passed in as a parameter on line 15, it logs the event/res
Callback functions are a little bit tricky to understand at first, but basically it let's you pass a function into another function as a parameter. The function you pass in gets then called from inside the function called.
function doCallBack(cb){
cb()
}
doCallBack(()=>{
console.log("i got called from within doCallBack")
})
connect
is declared on line 2, and then called on line 15. which means it will start running as soon as the page is loaded.