开发者

Uncaught TypeError in Chrome and Not a Function in FireFox

开发者 https://www.devze.com 2023-02-06 00:03 出处:网络
I want to set the variable zoom as the map.GetZoom() but I have been getting the following error in both Chrome and Firefox:

I want to set the variable zoom as the map.GetZoom() but I have been getting the following error in both Chrome and Firefox:

Chrome

Uncaught TypeError: Object # has no method 'getZoom'

Firefox

gmap.getZoom is not a function

zoom = gmap.getZoom();

First question What error did I make in my codes?

default.js

window.gmap = {
 zoom_Changed: function() {

 zoom = gmap.getZoom();

 if(zoom > 15) {
  document.write("hello");
 } else {
 } 
 }
};

Edit: Gmap is defined in my views.py and the zoom_Changed func开发者_如何学Ction is for the event listener in my views.py.

views.py

maps.event.addListener(gmap, 'zoom_changed', 'gmap.zoom_Changed');


Instead of zoom = gmap.getZoom();, it should be zoom = this.getZoom();.


is it getZoom() or GetZoom()? Casing is different in the question and the code example.

what @silverbtf is saying is partially right, i believe, (hard for me to test on the netbook i'm on). however by setting gmap again to an object literal (window.gmap = {...}), you're wiping out any existing gmap variable attached to the window object.

you could possibly rewrite your code like this:

gmap.zoom_Changed = function () {
    var zoom = this.getZoom(); // or .GetZoom()
    if (zoom > 15) {
        console.log('over 15');
    } else {
        console.log('under 15');
    }
}

this way, you're attaching a new method to the already existing gmap instead of blowing it away.

0

精彩评论

暂无评论...
验证码 换一张
取 消