javascript - Data Objects & classes -
hi wondering need create multiple data object variables on lots of different javascript file throughout project have same keys. these object used data source package have use. example
{ v1: 0, v2: 0, v3: 0. }
i thinking of using javascript classes dont know if correct way so. like
var = new ivar();
so created class
class outputdata { constructor(){ this.o0 = 0; this.o1 = 0; this.o2 = 0; this.o3 = 0; this.o4 = 0; this.o5 = 0; this.o6 = 0; this.o7 = 0; this.o8 = 0; this.o9 = 0; this.o10 = 0; this.o11 = 0; this.o12 = 0; } }
i imported file wanted use on lie so.
import '../outputdataclass.js'; var openingdeb = new outputdata();
but
uncaught referenceerror: outputdata not defined(…)
not sure why. reason wanted objects initialized data can use loop later on iterate trough object call function set correct values using key , reactive tracker. not sure if correct way go doing still learning if can educate me on great. have done research on javascript classes example create class locally on same file call not need.
thanks
the issue isn't class definition (as far can tell, it's fine!) - it's understanding of how es2015 import syntax works. there's no 'global scope' speak - if want export/import something, have explicit it, so:
file 1:
export default class outputdata { constructor(){ ... } }
file 2:
import outputdata '../outputdataclass.js'; var openingdeb = new outputdata();
Comments
Post a Comment