从关闭功能调用方法

我有一个CoffeeScript的类:

class window.MapHandler map = null makeMap: () -> latlng = new google.maps.LatLng(54.711929,20.5089); myOptions = zoom: 12 center: latlng mapTypeId: google.maps.MapTypeId.ROADMAP map = new google.maps.Map(document.getElementById("map_canvas"), myOptions) @geocode("Калининград, Чернышевского 101") placeMarker: (location) -> marker = new google.maps.Marker( position: location map: @map) geocode: (address) -> geocoder = new google.maps.Geocoder geocoder.geocode( 'address': address, (results, status) -> if status is google.maps.GeocoderStatus.OK map.setCenter(results[0].geometry.location) @placeMarker(results[0].geometry.location) else alert("Geocode was not successful for the following reason: " + status); )

有一个问题,当我打电话从匿名函数placeMarker方法与地理编码方法:visualizer.js:37Uncaught类型错误:对象[对象DOMWindow]没有方法'placeMarker“

我怎样才能调用这个方法?

--------------解决方案-------------

geocode: (address) ->
geocoder = new google.maps.Geocoder
geocoder.geocode(
'address': address,
(results, status) =>
if status is google.maps.GeocoderStatus.OK
map.setCenter(results[0].geometry.location)
@placeMarker(results[0].geometry.location)
else alert("Geocode was not successful for the following reason: " + status);
)

注意第5行脂肪箭头-它保留this@闭包中。

分类:JavaScript的 时间:2015-03-14 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.609 (s). 10 q(s)