I have a complex user interface structure that is dynamically controlled and says that I have a ui_state object where I save the userβs last state of the user interface, such as the tab was visible, what is inside this tab, etc.
For example:
var ui_states = { tabs : [ { name : "some tab", active : true, children : { ... } }, { name : "some other tab", children : { ... } } ] }
I save this to html5 localStorage , and when the user refreshes the site, he opens the page again. And every time the user interface changes this object, it changes accordingly. And right after changing it, I need to run let say updateLocalStorage() , which works fine.
My question is for this thread, can I create my own event for my ui_states object, something like ui_states.addEventListener('onchange', function(){ // do stuff }) so as not to run this updateLocalStorage() function every time when do i manipulate an object?
Thank.
javascript javascript-events event-handling events
KakambaWeb Oct 11 '10 at 2:43
source share