Instead triggering an event based on user action can you just listen for changes to an object and react then?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.