Create a class with metho events
Hi all!
I don't know if this is a pure question of jquery or is a navite javascript language skill, but I'd like to implement a class in javascript with events that works as follows:
- function myClass() {
- //Private properties
- var priv1;
- var priv2;
- ...
- //A public method that performs an ajax call:
- this.asycnCall = function() {
- $.ajax(.....
- ).done(function(res) {
- // This makes something that ensures that the data will be ready to call outer this class
- });
- }
- //An event handler
- this.onDataReadyAfterAsyncCall = function() {
- .... //The res returnet in asyncCall is ready here
- }
- }
Then, the main idea is to create an object to can access to the res variable as a method:
- var obj = new myClass();
- obj.asyncCall();
- obj.onDataReadyAfterAsyncCall = function(res) {
- // The res returned in asyncCall is accessible here!
- }
I don't know if this is explicit, hope yes! ;)
Thanks,
Dani, from Barcelona