So Safari keeps yelling at me for one specific error.
I'm trying to use Google Maps API and call map.getCenter();
. However sometimes, this happens before the map
has been fully loaded.
So instead in my function I test for an undefined
call like this:
if (map.getCenter() != undefined)
But that still errors out because I guess it doesn't even like making the call just to test the if the result is undefined
or not?
Can I get some help here?
Thanks!
I actually prefer something along these lines.
if(typeof myfunc == 'function') { myfunc(); }
Just because something isn't undefined doesn't make it a function.
if (typeof map !== 'undefined' && map.getCenter) { // code for both map and map.getCenter exists } else { // if they dont exist }
This is the right way to check for existence of a function.. Calling the function to test its existence will result in an error.
UPDATE: Snippet updated.
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