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:
- var A = {
- var1 : 1,
- f1 : function() {
- alert(this.var1) //will fail when event calling f1 directly
- alert(A.var1) //will always work
- }
- };
- $(window).ready(A.f1);
now the new behavior:
- var A = {
- var1 : 1,
- f1 : function() {
- alert(this.var1); //should not fail if event calling f1 directly
- alert(A.var1); //will always work
- alert(this.DOMref); //should output the DOM object witch triggered the event
- }
- };
- $(window).ready(A.f1,"DOMref");