Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

differences between MVCarray and array

I have been looking up the differences between MVCArray and Array for Google map API, but I haven't found any concrete.

I kind of get that MVCArray is a better option since it keeps track of changes (somehow) and have some kind of special events. And some of the same methods have slightly different names, e.g. array.length and MVCarray.getLength().

But can someone please explain in layman's term the explicit differences between the two? and it would be great if you could give some simple examples to make it easier to understand.

Thank you!

like image 755
lazy bum Avatar asked Mar 28 '17 08:03

lazy bum


People also ask

What is MVCArray?

An MVCArray inherits from MVCObject so you can set or get its properties, bind some of them, be binded by other objects, etc. But also, it implements some extras. It implements several of the methods you could use in a native javascript array, like push , pop , forEach , etc, so several google.

What is the difference between array and List in Javascript?

Arrays are specially optimised for arithmetic computations so if you're going to perform similar operations you should consider using an array instead of a list. Also lists are containers for elements having differing data types but arrays are used as containers for elements of the same data type.

How do you get to the center on Google Maps?

// Map center point can be fetched using the ui. Map. getCenter method. print('defaultMap center as a Point geometry', defaultMap.


1 Answers

To explain MVCArrays it's important to understand MVCObjects.

MVCObject is one of the "keystone" classes google maps is built on. It's like a plain object with setters and getters for its properties (nothing special so far), but what makes it special is that:

  1. You can add a listener to detect when any property is changed (with the set method) and execute a callback function
  2. You can bind any of its properties to another property of other MVCObject (or any class that inherits from this one)
  3. Other MVCObjects (or any class that inherit from this one) can have its properties binded to the ones in the current one.

So, basically, MVCObjects are observable-bindable objetcs.

An MVCArray inherits from MVCObject so you can set or get its properties, bind some of them, be binded by other objects, etc. But also, it implements some extras

  • It implements several of the methods you could use in a native javascript array, like push, pop, forEach, etc, so several google.maps methods can accept either an MVCArray or a native array, since it will use the same methods to traverse them.
  • It has an array property (that you can access with getArray method) that is a native js array. array-like methods as mentioned above are forwarded to this array.
  • It implements a set of events so you can detect when an element in the underlying array is set, removed or changed.

So, basically, MVCArrays are observable arrays. And since it inherits from MVCObject, their properties are also bindable

like image 195
ffflabs Avatar answered Sep 30 '22 17:09

ffflabs