Create a class with metho events

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:
  1. function myClass() {
  2.       //Private properties
  3.       var priv1;
  4.       var priv2;
  5.       ...

  6.       //A public method that performs an ajax call:
  7.       this.asycnCall = function() {
  8.             $.ajax(.....
  9.             ).done(function(res) {
  10.                   // This makes something that ensures that the data will be ready to call outer this class
  11.             });
  12.       }

  13.       //An event handler
  14.       this.onDataReadyAfterAsyncCall = function() {
  15.                   .... //The res returnet in asyncCall is ready here
  16.       }
  17. }


Then, the main idea is to create an object to can access to the res variable as a method:

  1. var obj = new myClass();
  2. obj.asyncCall();
  3. obj.onDataReadyAfterAsyncCall = function(res) {
  4.       // The res returned in asyncCall is accessible here!
  5. }
I don't know if this is explicit, hope yes! ;)

Thanks,

Dani, from Barcelona