dojo - Best practices when defining JavaScript variables -


when setting dojo application, recommended best practice initiating variables in reference dom objects? i've found need reference parent , children objects on top of widget , have been creating global placeholders following code.

var formitems = ["item_1", "item_2", "item_3", ... "item_15"];  formitems.foreach(function(formitem) {     var items = ["frm", "dom", "dijit"];     items.foreach(function(item) {         var x = item + formitem;         window[x] = undefined;     }); });  

vs

var frmitem_1, frmitem_2, frmitem_3, ... frmitem_15; var domitem_1, domitem_2, domitem_3, ... domitem_15; var dijititem_1, dijititem_2, dijititem_3, ... dijititem_15; 

the variables populated later in dojo application after has been parsed @ "save", jshint becomes upset due no actual explicit variables being defined.

i don't either of options. prefer have few global variables absolutely necessary. i'd recommend initializing array store items, referencing array in dojo application.

var formitems = []; for(var = 0; < 15; i++) {    formitems.push({        frm: null,        dom: null,        dijit: null    }); } 

and in dojo application replace:

  • frmitem_n formitems[n].frm
  • domitem_n formitems[n].dom
  • dijititem_n formitems[n].dijit

you might able avoid pre-populating array if can make dojo application push items array necessary. there may more work can make formitems array non-global, it's hard tell code provided.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -