【发布时间】:2012-05-06 16:43:47
【问题描述】:
我正在用 ruby on rails 制作一个应用程序,这是我的咖啡脚本文件之一
我相信我的代码已正确缩进,但仍然出现错误。
我在下面的评论中标记了给我错误的行。
请帮忙!
jQuery ->
today_date = new Date()
month = today_date.getMonth()
day = today_date.getDay()
pkpstyle= [
featureType: "landscape.natural"
elementType: "geometry"
stylers: [
lightness: -29
,
hue: "#ffee00"
,
saturation: 54
]
,
featureType: "poi.park"
stylers: [
lightness: -35
,
hue: "#005eff"
]
,
featureType: "road.arterial"
,
featureType: "road.arterial"
stylers: [ lightness: 45 ]
]
tempDay = 4
//I get an error here saying Uncaught TypeError: undefined is not a function
today_latlng = getLatlng(stops[tempDay])
markericon = new google.maps.MarkerImage("/assets/cycling.png")
myOptions =
center: today_latlng
zoom: 12
minZoom: 4
styles: pkpstyle
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions)
for i of stops
latlng = getLatlng(stops[i].latlng)
marker = new google.maps.Marker(
map: map
icon: markericon
position: latlng
)
getLatlng = (loc) ->
loc_split = loc.split(", ")
lat = loc_split[0]
lng = loc_split[1]
new google.maps.LatLng(lat, lng)
【问题讨论】:
-
getLatLong 在此处计算为未定义。有什么问题? (Coffeescript 允许这样的前向声明吗?JavaScript 中的 FunctionStatements but not "var f = func" 语句允许前向声明。JS 的最终结果是什么?我想像
var.. . 因此undefined.) -
您是否将此代码从 Javascript 转换为 CoffeeScript?
标签: javascript google-maps-api-3 coffeescript