Reference javascript object in its variables when declaring it -


i have object defined this:

function company(announcementid, callback){     this.url = 'https://poit.bolagsverket.se/poit/publiksokkungorelse.do?method=presenterakungorelse&diarienummer_presentera='+announcementid;     self =     gm_xmlhttprequest({         method: "get",         url: this.url,         onload: function(data) {             self.data = data;             callback();         }     }) } 

on callback, wish reference method object called "callbacktest", i'm trying this?

    var mycompany = new company(announcementid, callbacktest); 

if anonymous function, have written mycompany.callbacktest() how reference "mycompany" within variables?

until reference returned constructor mycompany, can't access argument.

so, "anonymous function" alluded way accomplish have access variable, have reference:

var mycompany = new company(announcementid, function () {     mycompany.callbacktest(); }); 

or, maybe move request work , callback method.

function company(announcementid){     this.url = 'https://poit.bolagsverket.se/poit/publiksokkungorelse.do?method=presenterakungorelse&diarienummer_presentera='+announcementid; }  company.prototype.request = function (callback) {     var self = this;     gm_xmlhttprequest({         method: "get",         url: this.url,         onload: function(data) {             self.data = data;             callback();             // or: callback.call(self);         }     }) };  company.prototype.callbacktest = function (...) { ... };  // ...  var mycompany = new company(announcementid); mycompany.request(mycompany.callbacktest); 

note: may need .bind() method when passing .request().

mycompany.request(mycompany.callbacktest.bind(mycompany)); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -