开发者

Binding class method to event in google maps v3?

开发者 https://www.devze.com 2023-01-03 20:36 出处:网络
In V2 of the Google Maps API, you could bind map events to a class method using the GEvent.bind function:

In V2 of the Google Maps API, you could bind map events to a class method using the GEvent.bind function:

GEvent.bind(this.drag_marker, "dragstart", this, this.start_dragging_route);

In the example above pretend that's a link from a prototype.init function, where start_dragging_route is a method inside the class.

It appears that开发者_运维技巧 the bind method doesn't exist anymore, at least not in the documentation. If it's true I have one way to solve it, but it's a touch ugly so I'd love to hear some other solutions to this problem.

How can I implement the GEvent.bind function in Google Maps API V3?


Oh right. Closures. Duh.

var self = this;
google.maps.event.addListener(this.drag_marker, "dragstart", function(latlng) {
    self.start_dragging_route(latlng);
});
0

精彩评论

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