Changing behavior of events to use something else than this

Changing behavior of events to use something else than this

If you use events the this reference is overwritten with the
triggering DOM object. In classes this is not very useful because a
direct called function looses their this reference. My suggestion is
to give the user a method to change the behavior of events in the way
that the user can set a new name where the DOM object reference is
saved. For Example:

  1. var A = {
  2.  var1 : 1,
  3.  f1 : function() {
  4.  alert(this.var1) //will fail when event calling f1 directly
  5.  alert(A.var1) //will always work
  6.  }
  7. };
  8. $(window).ready(A.f1);

now the new behavior:

  1. var A = {
  2.  var1 : 1,
  3.  f1 : function() {
  4.  alert(this.var1); //should not fail if event calling f1 directly
  5.  alert(A.var1); //will always work
  6.  alert(this.DOMref); //should output the DOM object witch triggered the event
  7.  }
  8. };
  9. $(window).ready(A.f1,"DOMref");