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!
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.
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.
// Map center point can be fetched using the ui. Map. getCenter method. print('defaultMap center as a Point geometry', defaultMap.
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:
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
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.getArray
method) that is a native js array. array-like methods as mentioned above are forwarded to this array.So, basically, MVCArrays are observable arrays. And since it inherits from MVCObject, their properties are also bindable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With