javascript - Define a unique global function when instantiating a class and pass data to it? -


i'm working api requires global function it's callback.

i define callback within class, can instantiated several times on same page.

submitform = function(el) {     this.el = $(el); };  submitform.prototype.api = function(){     grecaptcha.render(this.el,{      'sitekey' : '6lfk4sataaaaamskuioobffgclr_teruvbsr3pun',       'callback': callbackfunction    }); }; 

where callbackfunncton references function window.callbackfunction

how can i, every instance of class create unique global callback function , pass this.el function?

i'm thinking maybe naming function random number, not sure if can pass this.el function somehow.

submitform = function(el) {     this.el = $(el);     this.rand = math.random(); };  submitform.prototype.api = function(){     grecaptcha.render(this.el,{      'sitekey' : '6lfk4sataaaaamskuioobffgclr_teruvbsr3pun',       'callback': callbackfunction    }); };  window[this.rand] = function(this.el){    ... } 

you create object holds functions like

window.mycallbackfunctions = new object(); 

then add static variable class count instances

submitform.instancecount 

every new instance assign new callbackfunction

window.mycallbackfunctions[submitform.instancecount] = function(obj) {}; 

you can't "pass" directly "this.el". has done callback.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -