the question seems very primitive but i am new to javascript and vuejs. as shown in the code posted below,i am creating a class DigitizePolygonInteractions
that extends MapBuilder
. the constructor receives two parameters moduleName
and mapInstance
.
i want to assign the parameter mapInstance
that is passed to the constructor to a local private variable named mapInstance
as well. as for the code posted below, visual-studio codes does not highlight the let mapInstance
when the following line of code
is added this.mapInstance = mapInstance
, which indicates that this.mapInstance
is not used.
in java, given the code posted below, for the statement this.mapInstance = mapInstance
, this.mapInstance
refers to let mapInstance
while mapInstance
refers to mapInstance
that is passed to the constructor
how can i achieve the same in javascript please
code:
let instance;
let mapInstance //<==should be the local private variable
export class DigitizePolygonInteractions extends MapBuilder {
/**
* @param { string } moduleName like 'map-sen2bee'
*/
constructor(moduleName,mapInstance) {
super(moduleName);
instance = this
this.mapInstance = mapInstance //<==============here
}
2
Answers
However, a better approach would be:
I haven’t worked with classes that much, but I can try to explain it with a very simple example below;