DEV Community

Discussion on: "Let me wait-for-it and call you back", said wait-for-it.js

Collapse
 
ivan_jrmc profile image
Ivan Jeremic • Edited

Can you explain this JavaScript to me in your source code?

cb = observeNodes[selector].pop();
cb();
Enter fullscreen mode Exit fullscreen mode

I never saw that you can call something that is eighter a variable or a function, why not

const cb = observeNodes[selector].pop();
cb();
Enter fullscreen mode Exit fullscreen mode

Also is this library usable for React? Or only Vanilla JS?

Thanks

Collapse
 
cstayyab profile image
Muhammad Tayyab Sheikh • Edited

A reference to function is being stored in observerNode[selector] and pop is being used to get that reference and store into cb (callback) hence when you call cb it actually calls that function. And yes it is a very valid syntax in JavaScript.

I have only tested it fir Vanilla JS