javascript - Is there a way to guess if some global variables have been assigned? -


in javascript, if declare constructor this:

var pmfont = function(text, font, size) {     this.text = text;     this.font = font;     this.size = size;     /*     ...     ton of code     ...     */     x = 15; }; var test = new pmfont('dd', 'arial', 92); 

and create global variable example above: x = 15;, there way know, once object has been created, if there new global variables have been created?

i've downloaded code, , i'd know if there useless variables in example stay in memory. may run far worse problems, example:

imgd = ctx.getimagedata(0, 0, this.basewidth, this.baseheight) 

...gets data of html5 canvas 2d context, , if it's not freed takes lot of ram.

since js variables default undefined, if term assigned, previous answers not precise:

function isgloballydefined(varname) {    return window[varname] !== undefined  } 

if variable has null or false value, has been assigned piece of code.

since didn't specify context, depending running code, window object might not available, if want use in node context, want variable in global object.

hope helps.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -