Message from JavaScript discussions
September 2018
— For asynchronous functions where you don't control when the function is done, you can pass the callback, and it will be called when it's done
asyncFunction(param1, param2, callback)
// someOtherStuff...
asyncFunction
is called, but you don't wait for it to complete. someOtherStuff
continues to happen, and whenever asyncFunction
is done running, it will call callback
which is also a function
— Does that make sense Adan?
— Thank you
— No, querySelectorAll obviously does more work
— ?
— Where is the test?
— It may do more work, but getElementsByClassName may be doing even more work🤤
— ClassName takes a class name, querySelector takes a query, which it has to parse
— To find potentially classnames, potentially other stuff
— And THEN it executes what it parsed
— But still htmlcollection updates itself when any dom node with the corresponding classname gets added later on. Maybe elementsByClassName is initially faster but I still think queryselctorall is overall faster. And when you just use querySelectorAll(".foo") instead of getElementsByClassName("foo") it shouldnt be a real performance difference. In the jsperf test it was supposed to be way faster.