javascript - How to pass object context to .on() callback function -


i'm working on structuring javascript using module pattern explained here.

this simplified version of code:

var obj = {   binduiactions: function(){     $('#button').on('click', {self: this}, this.dostuff);   },   dostuff: function(e){     $(this).fadeout();     var self = e.data.self;     self.dosomethingelse();   },   dosomethingelse: function(){     //....   } } 

i need pass object context dostuff method because don't want use:

obj.dosomethingelse(); 

so can use code again somewhere else, or change object name ('obj') later on. using event data not feel best solution, there better way done?

i've used $.proxy change context .on() callback function , works. problem need keep context click-element also,

$(this).fadeout(); 

to work.

thanks in advance!

i think set context 1 of these:


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -