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.