Empty properties of a polyline type object?

1

Empty properties of a polilyne type object

I need to empty a polilyne type object so that it can be reused as many times as needed, I want the properties to remain empty, for example the object when you have values has something like that

linea = {
ruta: [coor1, coor2, coor3],
origen: cdmx,
destino: colima

}

What I want is to empty that object and let me stay like this:

linea = {
camino: [],
origen
destino
}

I am using javascript and the javascript api of google maps version 3. The form setMap (null), does not help me since it only hides the line but the object is still there with its assigned values.

    
asked by Jonathan Rivera Diaz 23.09.2017 в 02:21
source

2 answers

1

Try creating a method within the object that cleans its properties:

var linea = {
    ruta: [coor1, coor2, coor3],
    origen: cdmx,
    destino: colima,
    clear:function()
    {
        this.ruta = [];
        this.origen = "";
        this.destino = ""   
    }
}

Then you just have to call the cleary method to clean up the content:

linea.clear();

Working example:

var linea = {
  ruta: [33, 44, 55],
  origen: 22,
  destino: 33,
  clear:function()
  {
    this.ruta = [];
    this.origen = "";
    this.destino = ""	
  }
};

linea.clear();

console.log(linea);

linea.ruta.push(3);
linea.ruta.push(55);

console.log(linea);
linea.clear();
console.log(linea);

Although I personally do not see problems with creating a new object since the GC would delete the last reference.

    
answered by 23.09.2017 в 17:19
0

you can access its attributes, assign values independently

to access its attributes refer to the point followed by the attribute you want to obtain.

var linea = {
camino: [1,2,4],
origen:'',
destino:''
};
console.log(linea);

linea.camino=[];

console.log(linea);
    
answered by 23.09.2017 в 02:30