3 ms·
A demo of sorts: http://quickenloans.github.io/Behaviors.js/ http://quickenloans.github.io/Behaviors.js/ The code will look extremely non-idiomatic to most fr
by romaniv 10y ago
A demo of sorts:
http://quickenloans.github.io/Behaviors.js/ http://quickenloans.github.io/Behaviors.js/
The code will look extremely non-idiomatic to most frontend engineers. Treat it as a thought experiment (which it is). The important thing isn't the particular implementation, but the ideas I outlined above. There are other, often simpler, ways to implement the same concepts.
One property of these libraries that might not be immediately obvious is that they "automatically" adapt to changes on the page. So you can add an element with a behavior via AJAX or dev tools and it will actually work. This is why using timers and global events is a part of that list.
Another thing is that none of these libraries have an API or modify the global JS namespace. This is part of the thought experiment not directly related to the main concepts. It drives some of the complexity.
Edit: Fixed the link.