Instead triggering an event based on user action can you just listen for changes to an object and react then?
The watch() method watches for the event in which a property gets assigned a value.
Well, depending on the domain you're working with, you can use backbone.js - it has a "model" object that you can extend and connect up to callbacks that get triggered by events automatically when the model is changed - that is, you set a field on the model, and it will automatically fire an event that you can listen to. You have to define your models to extend its Model, and call a setter function instead of setting properties directly, but it's very useful, I recommend it.
Just for clarity's sake, the event is fired from the model on change, so it's fired even if you set the value of the attribute programmatically or in the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With